quarkusio/quarkus · error · IllegalArgumentException
Error loading naming strategy: ${strategy.substringAfter('.
Error message
Error loading naming strategy: ${strategy.substringAfter('.')} What it means
This is thrown by JsonProducer.loadStrategyClass when Quarkus tries to instantiate a user-configured JSON naming strategy class (quarkus.rest.kotlin-serialization.naming-strategy) but loading or constructing it via reflection fails. The underlying ReflectiveOperationException (ClassNotFound, no no-arg constructor, etc.) is wrapped into an IllegalArgumentException naming the strategy's short name.
Source
Thrown at extensions/resteasy-reactive/rest-kotlin-serialization-common/runtime/src/main/kotlin/io/quarkus/resteasy/reactive/kotlin/serialization/common/runtime/JsonProducer.kt:89
jsonProducer.loadStrategyClass(strategy)
},
)
}
@ExperimentalSerializationApi
private fun loadStrategyClass(strategy: String): JsonNamingStrategy {
try {
val strategyClass: Class<JsonNamingStrategy> =
Thread.currentThread().contextClassLoader.loadClass(strategy)
as Class<JsonNamingStrategy>
val constructor =
strategyClass.constructors.find { it.parameterCount == 0 }
?: throw ReflectiveOperationException(
"No no-arg constructor found on $strategy"
)
return constructor.newInstance() as JsonNamingStrategy
} catch (e: ReflectiveOperationException) {
throw IllegalArgumentException(
"Error loading naming strategy: ${strategy.substringAfter('.')}",
e,
)
}
}
@ExperimentalSerializationApi
private fun extractBuiltIn(strategy: String): JsonNamingStrategy {
val kClass = Builtins::class
val property =
kClass.memberProperties.find { property ->
property.name == strategy.substringAfter('.')
}
?: throw IllegalArgumentException(
"Unknown naming strategy provided: ${strategy.substringAfter('.')}"
)
return property.get(JsonNamingStrategy) as JsonNamingStrategyView on GitHub (pinned to e1c734241f)
Solutions
- Verify the configured class exists and is on the runtime classpath (check package/name spelling).
- Give the class a public no-arg constructor and make it implement kotlinx.serialization.json.JsonNamingStrategy.
- If using a built-in strategy, use the Builtins form (e.g. JsonNamingStrategy.Builtins.snake_case) instead of a custom class name.
- For native builds, register the class for reflection (@RegisterForReflection).
Example fix
// before
@ConfigProperty(name = "quarkus.rest.kotlin-serialization.naming-strategy")
// com.example.MyStrategy (has only a constructor taking a String)
class MyStrategy(private val cfg: String) : JsonNamingStrategy { ... }
// after
class MyStrategy : JsonNamingStrategy { ... } // public no-arg ctor Defensive patterns
Strategy: validation
Validate before calling
// before configuring
val klass = runCatching { Class.forName("com.example.MyStrategy") }.getOrNull()
check(klass != null) { "naming strategy class not on classpath" }
check(klass.constructors.any { it.parameterCount == 0 }) { "needs a public no-arg constructor" }
check(JsonNamingStrategy::class.java.isAssignableFrom(klass)) Type guard
fun Class<*>.isValidNamingStrategy() =
JsonNamingStrategy::class.java.isAssignableFrom(this) && constructors.any { it.parameterCount == 0 } Prevention
- Prefer built-in strategy names over custom classes
- Keep strategy classes with public no-arg constructors
- Add reflection registration for native builds
When it happens
Trigger: Setting quarkus.rest.kotlin-serialization.naming-strategy to a fully-qualified custom class name that does not exist on the classpath, is not public, lacks a no-arg constructor, or is not a JsonNamingStrategy.
Common situations: Typos in the config value; pointing at a class from a dependency not present at runtime; writing a constructor with args (e.g. to receive config); refactor renamed the strategy class but the property was not updated; native-image builds missing reflection registration.
Related errors
- Unknown naming strategy provided: ${strategy.substringAfter
- Failed to set dev services config
- Failed to set dev services override config
- Unable to get element as unwrappedType is not a DeclaredType
- Suspendable @Blocking methods are not supported yet: %s.%s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/2e601c7bdbc5dabe.
Report an issue: GitHub.