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

deserialized JsonAnySetter field is null #4508

Open
1 task done
MaximValeev opened this issue Apr 30, 2024 · 5 comments
Open
1 task done

deserialized JsonAnySetter field is null #4508

MaximValeev opened this issue Apr 30, 2024 · 5 comments
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@MaximValeev
Copy link

MaximValeev commented Apr 30, 2024

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

@MaximValeev MaximValeev added the to-evaluate Issue that has been received but not yet evaluated label Apr 30, 2024
@JooHyukKim
Copy link
Member

JooHyukKim commented May 1, 2024

Since additionalProperties has default value of null, we can say either...

  • field is deserialized to null
  • field is not deserialized, so deafult to null

Could you provide Java-only reproduction to make sure it is jackson-databind issue, @MaximValeev ?
There is separate kotlin repo FYI.

@cowtowncoder
Copy link
Member

Right; either this needs to move to jackson-module-kotlin (I can transfer if so), or reproduction should be in Java.

But I think there is probably already an issue wrt @JsonAnySetter not working with Creator properties -- and even PR to potentially fix that.

@kotcrab
Copy link

kotcrab commented May 13, 2024

I also ran into this issue, it can be fixed by writing @field:JsonAnySetter. In 2.17.0 ElementType.PARAMETER was added to the @Target list of JsonAnySetter, 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
Copy link
Member

Ah, thank u for sharing @kotcrab !

@JooHyukKim
Copy link
Member

Some background.

As @kotcrab described above, this is regression caused by annotations module change, the annotation change was meant to be pre-requisite for the databind-module's Allow 'JsonAnySetter' to flow through JsonCreator #562 issue.

I started writing PR #4366 to support the databind-module change, but stopped to allow room for Property Introspection Rewrite in #4515.

As per solution, either....

  • revert adding ElementType.PARAMETER to JsonAnySetter or...
  • ask @k163377 if it's possible to make changes so that Kotlin module can discover @JsonAnySetter without @field: declaration. Or maybe @cowtowncoder knows the proper extension point for JsonAnySetter discovery?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

4 participants