FasterXML / jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Apache License 2.0
1.11k stars 175 forks source link

Field with value class typ ignoring JsonProperty binding #791

Closed bboschrek closed 3 months ago

bboschrek commented 3 months ago

Search before asking

Describe the bug

I use value class for the field type. I have that type annotated by JsonProperty for assigning mapping to some other field name in JSON. But it seems that it is ignored and is used field name in class for the search field in JSON.

Edit: it happened also for other fields in object which aren't value class

Edit2: when I use @field:JsonProperty(...) on all fields in class it works as expected...but it is bad

error:

Instantiation of [simple type, class com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult$Symbol] value failed for JSON property exchangeTimezone due to missing (therefore NULL) value for creator parameter exchangeTimezone which is a non-nullable type at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult["data"]->java.util.ArrayList[0]-com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult$Symbol["exchangeTimezone"]) com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult$Symbol] value failed for JSON property exchangeTimezone due to missing (therefore NULL) value for creator parameter exchangeTimezone which is a non-nullable type at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult["data"]->java.util.ArrayList[0]-com.xyz.api.financial.adapter.output.sadd.client.dto.SymbolSearchResult$Symbol["exchangeTimezone"]) at com.fasterxml.jackson.module.kotlin.KotlinValueInstantiator.createFromObjectWith(KotlinValueInstantiator.kt:97)

To Reproduce

@JvmInline
value class CurrencyCodeTw(val twCurrencyCode: String)

 data class Symbol(
 @JsonProperty("currency") val currencyCode: CurrencyCodeTw,
@JsonProperty("exchange_timezone") val exchangeTimezone: String
)

Expected behavior

No response

Versions

Kotlin: 1.9 Jackson-module-kotlin: 2.17.0 Jackson-databind:

Additional context

No response

k163377 commented 3 months ago

Closed as a duplicate of #651