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

@JsonPropery ignored when using global naming strategy #883

Closed
Myshkouski opened this issue Jul 2, 2024 · 0 comments · Fixed by #884
Closed

@JsonPropery ignored when using global naming strategy #883

Myshkouski opened this issue Jul 2, 2024 · 0 comments · Fixed by #884

Comments

@Myshkouski
Copy link
Contributor

Myshkouski commented Jul 2, 2024

Expected Behavior

Property names from @JsonProperty or @JsonbProperty should take precedence over property name, translated by PropertyNamingStrategy.

Let's take a look at the following case:

  1. DTO class:
// doc-examples/example-kotlin/src/test/kotlin/example/BookTest.kt
@Serdeable
data class Book (
    val title: String,
    @JsonProperty("qty") val quantity: Int
)
  1. Define app configuration:
# doc-examples/example-kotlin/src/test/resources/application.properties
micronaut.serde.property-naming-strategy=SNAKE_CASE
  1. Run test:
// doc-examples/example-kotlin/src/test/kotlin/example/BookTest.kt:12
val result = objectMapper.writeValueAsString(Book("The Stand", 50))

result should be {"title":"The Stand","qty":50} with explicit property name qty, set by @JsonProperty.

Actual Behaviour

Actual result is {"title":"The Stand","quantity":50}. Annotation property names are ignored.

Steps To Reproduce

  1. Copy this fork:
git clone https://github.com/Myshkouski/micronaut-serialization
  1. Checkout this revision from fork:
git checkout 425696c939401fc74b1ccf89df120793f37e85fb
  1. Run tests from io.micronaut.serde.jackson.GlobalPropertyStrategySpec:
./gradlew :micronaut-serde-jackson:test --tests "io.micronaut.serde.jackson.GlobalPropertyStrategySpec"
  1. 'test global property strategy SNAKE_CASE with JsonProperty annotated fields' will fail:
Test Run :micronaut-serde-jackson:test > Partition 1 in session 1 on localhost-executor-1 > GlobalPropertyStrategySpec test global property strategy SNAKE_CASE with JsonProperty annotated fields FAILED

  Condition not satisfied:
  
  val == '{"explicit_foo_bar_prop_name":"hello","abc_xyz":123}'
  |   |
  |   false
  |   19 differences (63% similarity)
  |   {"(---------)foo_bar(----------)":"hello","abc_xyz":123}
  |   {"(explicit_)foo_bar(_prop_name)":"hello","abc_xyz":123}
  {"foo_bar":"hello","abc_xyz":123}
      at io.micronaut.serde.jackson.GlobalPropertyStrategySpec.test global property strategy SNAKE_CASE with JsonProperty annotated fields(GlobalPropertyStrategySpec.groovy:59)

Environment Information

No response

Example Application

https://github.com/Myshkouski/micronaut-serialization/tree/425696c939401fc74b1ccf89df120793f37e85fb

Version

4.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant