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

MN:4.4.0 - Changed behavior for @JsonGetter in @Introspected-annotated classes #10737

Closed
roar-skinderviken opened this issue Apr 18, 2024 · 6 comments
Assignees
Labels
type: regression A breaking change was introduced in a minor or patch release

Comments

@roar-skinderviken
Copy link

roar-skinderviken commented Apr 18, 2024

Expected Behavior

With the example application and MN:4.4.0, I expect this JSON as output from the controller.

{"afterCare":[{"klassifisering":{"regionKode":"01"},"stats":{"SomeField1":0,"SomeField2":0}}]}

Actual Behaviour

This is a simplistic reconstruction of what happened:

{"afterCare":[{"klassifisering":{"regionKode":"01"},"stats":{"SomeField1":0,"SomeField2":0}}]}

changed to

{"afterCare":[{"klassifisering":{"regionKode":"01"},"stats":{"shouldNotAppearInJson":{"SomeField1":0,"SomeField2":0}}}]}

with MN:4.4.0.

Steps To Reproduce

  1. In the example application, switch to MN:4.4.0 in gradle.properties.
  2. Start the application with ./gradlew clean run
  3. Open http://localhost:8080/get-aggregation

Observe that JSON has changed to

{"afterCare":[{"klassifisering":{"regionKode":"01"},"stats":{"shouldNotAppearInJson":{"SomeField1":0,"SomeField2":0}}}]}

Please note that removing @Introspected fixes the issue.

Environment Information

JDK 21
Kotlin 1.9.23
Ubuntu 22.04

Example Application

https://github.com/roar-skinderviken/MN-4.4-jackson-issue

Version

4.4.0

@roar-skinderviken roar-skinderviken changed the title MN:4.4.0 - Changed behavior for @JsonGetter MN:4.4.0 - Changed behavior for @JsonGetter in @Introspected-annotated classes Apr 18, 2024
@sdelamo sdelamo added the type: regression A breaking change was introduced in a minor or patch release label Apr 19, 2024
@timyates
Copy link
Member

@dstepanov Any ideas?

@dstepanov
Copy link
Contributor

It's probably some KSP stuff. I have added similar test to Micronaut Serialization and fixed some bug micronaut-projects/micronaut-serialization#826

@dstepanov
Copy link
Contributor

Looks like the annotation is not retained in the property annotations

@roar-skinderviken
Copy link
Author

Seems like you're right about KSP @dstepanov. When replacing it with kotlin("kapt") version "1.9.23", returned JSON is as expected.

@timyates
Copy link
Member

It might be us, as changing the field name in the reproducer to be different to the JsonGetter name seems to work

diff --git a/gradle.properties b/gradle.properties
index ab4cf7a..c3fd1bb 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,3 +1,3 @@
-micronautVersion=4.3.8
+micronautVersion=4.4.0
 kotlinVersion=1.9.23
 org.gradle.jvmargs=-Xmx4096M
diff --git a/src/main/kotlin/no/javatec/viewmodel/ClassificationAndStats.kt b/src/main/kotlin/no/javatec/viewmodel/ClassificationAndStats.kt
index 3972f0b..3ecf94a 100644
--- a/src/main/kotlin/no/javatec/viewmodel/ClassificationAndStats.kt
+++ b/src/main/kotlin/no/javatec/viewmodel/ClassificationAndStats.kt
@@ -9,8 +9,8 @@ data class ClassificationAndStats<out T : StatsEntry>(
     val klassifisering: ClassificationVars,
     /** Ignore field to avoid double wrapping of values in resulting JSON */
     @JsonIgnore
-    val stats: T
+    val spats: T
 ) {
     @JsonGetter("stats")
-    fun getValues(): Map<Aggregation, Int> = stats.shouldNotAppearInJson
+    fun getValues(): Map<Aggregation, Int> = spats.shouldNotAppearInJson
 }

@roar-skinderviken
Copy link
Author

roar-skinderviken commented Apr 22, 2024

Working now with MN:4.4.1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A breaking change was introduced in a minor or patch release
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants