jackson-databind: deserialized JsonAnySetter field is null
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
I have kotlin data class
data class Request(
@JsonProperty("header")
override val header: String? = null,
@JsonIgnore
@JsonAnySetter
@JsonAnyGetter
val additionProperties: Map<String, Any?>? = null,
) : Parent(header)
and json
{
"payloadType": "perform",
"data":{
"header": "lol",
"type": "sometype",
"any_other_data": {
"field1": "1",
"field2": "",
"field3": "",
"field4": {
"field5": "",
"field6": "",
"field7": "anytext"
}
}
}
}
Before jackson 2.17.0 the json deserialized into class correctly. any_other_data put to additionalProperties map. On 2.17.0 version i have additionalProperties == null after the deserialization.
Version Information
2.17.0
Expected behavior
i expected that field annotated with @JsonAnySetter will be filled with all the undeclared fields
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 9
- Comments: 22 (20 by maintainers)
Commits related to this issue
- Downgrade Jackson 2.18.0 to 2.17.2 Running Parcelo in a container via our current Dockerfile revealed that "uses-sdk" fields were not being parsed from applications' Android manifests, effectively pr... — committed to accrescent/parcelo by lberrymage 2 years ago
- Downgrade Jackson 2.18.0 to 2.17.2 Running Parcelo in a container via our current Dockerfile revealed that "uses-sdk" fields were not being parsed from applications' Android manifests, effectively pr... — committed to accrescent/parcelo by lberrymage 2 years ago
I also ran into this issue, it can be fixed by writing
@field:JsonAnySetter. In 2.17.0ElementType.PARAMETERwas added to the@Targetlist ofJsonAnySetter, this causes Kotlin to add this annotation to the constructor parameter instead of the field as described here if you don’t specify explicit use-site target.@JooHyukKim No; annotations are special case where we really cannot change things in patch release, so 2.17.x cannot be changed except in exceptional circumstances. Same now goes for 2.18.x, actually, since 2.18.0 is released.
But if #4720 can fix this issue let’s work on getting that done. I am not opposed to changes to Kotlin module but unfortunately don’t really know what to change, where and how.
I am bit worried tho about Kotlin annotation handling, wrt replication of annotations to accessors: we seem to be hitting problems related to that.
@mikethecalamity that is unfortunately not a full reproduction; would need to add calling code, as well as replace Lombok annotations with processed code (one JVM loads).
If this could be reproduced with plain-non-Lombok-Java that’d be great since so far assumption has been this is Kotlin-specific. But right now we do not have such test.
I’m seeing this issue when I tried to upgrade to
2.18.0, but it seems to e working fine in2.17.2.My class has lombok in it, but it looks like this:
@k163377 Yes, I think it’s matter of getting #562 resolved (via #4558) and then Kotlin side probably wants to have a test to verify things work there as expected. But hopefully no other work needed (but you never know before testing 😃 ).
I understood that there is nothing to do in
KotlinModuleas it is handled by #4558 .JsonAnyGetter/Setter will already not appear in the serialization/deserialization as its own property. The JsonIgnore is not necessary and should not be there