quarkusio/quarkus · error · ReflectiveOperationException
Could not find the namingStrategy property on JsonBuilder
Error message
Could not find the namingStrategy property on JsonBuilder
What it means
JsonProducer configures kotlinx.serialization Json naming strategies reflectively by setting the `namingStrategy` property on JsonBuilder. If the kotlinx.serialization version in use no longer exposes that mutable property (API change), the lookup returns null and a ReflectiveOperationException is thrown. This is a library-version compatibility failure, typically surfaced indirectly as IllegalArgumentException wrapping.
Source
Thrown at extensions/resteasy-reactive/rest-kotlin-serialization-common/runtime/src/main/kotlin/io/quarkus/resteasy/reactive/kotlin/serialization/common/runtime/JsonProducer.kt:60
configuration.json().namingStrategy().ifPresent { strategy ->
loadStrategy(this, strategy, this@JsonProducer)
}
val sortedCustomizers = sortCustomizersInDescendingPriorityOrder(customizers)
for (customizer in sortedCustomizers) {
customizer.customize(this)
}
}
@ExperimentalSerializationApi
private fun loadStrategy(
jsonBuilder: JsonBuilder,
strategy: String,
jsonProducer: JsonProducer,
) {
val strategyProperty: KMutableProperty1<JsonBuilder, JsonNamingStrategy> =
(JsonBuilder::class.memberProperties.find { member -> member.name == "namingStrategy" }
?: throw ReflectiveOperationException(
"Could not find the namingStrategy property on JsonBuilder"
))
as KMutableProperty1<JsonBuilder, JsonNamingStrategy>
strategyProperty.isAccessible = true
strategyProperty.set(
jsonBuilder,
if (strategy.startsWith("JsonNamingStrategy")) {
jsonProducer.extractBuiltIn(strategy)
} else {
jsonProducer.loadStrategyClass(strategy)
},
)
}
@ExperimentalSerializationApi
private fun loadStrategyClass(strategy: String): JsonNamingStrategy {
try {View on GitHub (pinned to e1c734241f)
Solutions
- Align kotlinx-serialization-json version with the one supported by your Quarkus version (check the Quarkus BOM)
- Construct the Json instance manually with Json { namingStrategy = ... } instead of relying on the CDI producer if versions cannot be aligned
- Upgrade Quarkus to a version compatible with your kotlinx-serialization version
- Remove the naming-strategy config to fall back to the default Json instance
Example fix
// before (config-driven, version-dependent)
quarkus.kotlin-serialization.json.naming-strategy=io.ktor...JsonNamingStrategy.SnakeCase
// after (explicit)
val json = Json { namingStrategy = JsonNamingStrategy.SnakeCase } Defensive patterns
Strategy: validation
Validate before calling
// Verify kotlinx-serialization exposes the property before configuring
val hasNamingStrategy = JsonBuilder::class.memberProperties.any { it.name == "namingStrategy" }
require(hasNamingStrategy) { "kotlinx-serialization version incompatible with naming-strategy config" } Type guard
fun JsonBuilder.hasNamingStrategy(): Boolean =
JsonBuilder::class.memberProperties.any { it.name == "namingStrategy" } Try / catch
try {
json = produceJson()
} catch (e: ReflectiveOperationException) {
json = Json.Default // fall back to default Json
} Prevention
- Align kotlinx-serialization-json with the Quarkus BOM version
- Prefer building Json explicitly over reflection-based config when possible
- Test naming-strategy config in CI after any dependency upgrade
When it happens
Trigger: Setting quarkus.kotlin-serialization.json.naming-strategy at build/runtime time with a kotlinx-serialization version whose JsonBuilder lacks the namingStrategy property, or where it is not a KMutableProperty1.
Common situations: Upgrading or downgrading kotlinx-serialization-json so its internal JsonBuilder API differs from what the Quarkus rest-kotlin-serialization-common extension expects; Quarkus/kotlinx version skew in a project BOM.
Related errors
- No no-arg constructor found on $strategy
- Unexpected index $index
- Unexpected index $index
- Error loading naming strategy: ${strategy.substringAfter('.
- Expected : after attribute
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/dbd6366db78d0427.
Report an issue: GitHub.