Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field with value class typ ignoring JsonProperty binding #791

Closed
1 of 3 tasks
bboschrek opened this issue Apr 17, 2024 · 1 comment
Closed
1 of 3 tasks

Field with value class typ ignoring JsonProperty binding #791

bboschrek opened this issue Apr 17, 2024 · 1 comment
Labels

Comments

@bboschrek
Copy link

bboschrek commented Apr 17, 2024

Search before asking

  • I searched in the issues and found nothing similar.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem only occurs when using Kotlin.

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

@bboschrek bboschrek added the bug label Apr 17, 2024
@k163377
Copy link
Contributor

k163377 commented Apr 18, 2024

Closed as a duplicate of #651

@k163377 k163377 closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants