You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deserializing JSON into a POJO, Optionals should be handled properly to allow detecting the absence/presence of a value (as needed on PATCH endpoints for example, where you want to differentiate between null and absence of a value).
This works fine, until I add @Introspected annotation to the POJO (which is required for Validations etc as well).
Example POJO
@Introspected
data classTestPojo(
valfield1:Optional<String>? = null,
valfield2:Optional<String>? = null
)
JSON
val output1 = objectMapper.readValue("{\"field1\": \"value1\", \"field2\": \"value2\"}", TestPojo::class.java)
val output2 = objectMapper.readValue("{\"field1\": null, \"field2\": \"value2\"}", TestPojo::class.java)
val output3 = objectMapper.readValue("{}", TestPojo::class.java)
When @Introspected is not used on the POJO, all is fine; however, when adding @Introspected to the POJO, both null and absent values are mapped to Optional.empty()
Expected Behavior
When deserializing JSON into a POJO, Optionals should be handled properly to allow detecting the absence/presence of a value (as needed on PATCH endpoints for example, where you want to differentiate between
null
and absence of a value).This works fine, until I add
@Introspected
annotation to the POJO (which is required for Validations etc as well).Example POJO
JSON
Output
Actual Behaviour
When
@Introspected
is not used on the POJO, all is fine; however, when adding@Introspected
to the POJO, bothnull
andabsent
values are mapped toOptional.empty()
Output
Steps To Reproduce
I added tests in the linked sample project (DemoTest.kt)
Environment Information
macOS 14.4.1
JDK 17
Example Application
https://github.com/cweinberger/micronaut-optionals-introspected-demo
Version
4.3.6
The text was updated successfully, but these errors were encountered: