Support deserializing json via jackson into kotlin classes that have default properties and use the default property values if missing #12193
+142
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found an bug recently in a Micronaut application I was writing where I was using the custom Micronaut object mapper, if a Kotlin class is annotated with
@Introspectedand the json payload is missing a primitive field, the class property's default value is ignored and the Jackson default primitive value is used. The Micronaut bean instantiation feature already supports instantiating a Kotlin class that has optional/default properties which this fix uses. If the parameter's constructor argument is not required and there is no value from the json payload in the value buffer, instead of having Jackson determine the default the primitive value, we just use null and have the bean instantiation functionality take over and use the default property value.This is my first pr to the project and I wasnt sure if I needed to create an issue before submitting a pr. If that is required, I can totally do that! Thanks!