Support single-Map @JsonAnySetter methods#6075
Conversation
|
Can you specify issue number on test methods? @goutamadwant See neighboring test cases as example |
75278f1 to
41e77d2
Compare
Thanks @JooHyukKim, updated the new test method names to include 4889, matching the neighboring test cases. Let me know if any suggestions. thanks! |
@JsonAnySetter methods
JooHyukKim
left a comment
There was a problem hiding this comment.
We need JavaDocs as well.
Thanks!
| PropertyMetadata.STD_OPTIONAL); | ||
| if (am.getParameterCount() == 1) { | ||
| JavaType paramType = am.getParameterType(0); | ||
| if (!paramType.isMapLikeType()) { |
There was a problem hiding this comment.
I think single argument doesn't always mean any-setter is intended?
| if (anyMethod.getParameterCount() == 1) { | ||
| Class<?> type = anyMethod.getRawParameterType(0); | ||
| if (!Map.class.isAssignableFrom(type)) { | ||
| throw new IllegalArgumentException(String.format( |
There was a problem hiding this comment.
Not sure if we can simply throw error, considering we are doing minor version fix...? 🤔
| throw new UnsupportedOperationException("Cannot call createParameterObject() on " + getClass().getName()); | ||
| } | ||
|
|
||
| public void finish(DeserializationContext ctxt, Object instance) throws JacksonException { } |
There was a problem hiding this comment.
Method name is generic too much.
Can we do both below?
- Change name
- Add JavaDoc
I'm talking about all finish methods
Fixes #4889
Root cause
@JsonAnySetterdiscovery handled fields, creator parameters, and two-argument setter methods, but explicitly annotated one-argument methods were still treated as regular setters. That meant a method likesetOther(Map<String, Object> other)was not recognized as an any-setter target.Change
This adds support for explicitly annotated single-argument
Mapany-setter methods. Unknown properties are collected into a map using the existing any-setter key/value deserialization flow, then the annotated method is invoked once with the collected values.Verification
./mvnw -q -Dtest=tools.jackson.databind.deser.AnySetterTest#testJsonAnySetterOnMapMethod test./mvnw -q -Dtest=tools.jackson.databind.deser.AnySetterTest test./mvnw -q -Dtest=tools.jackson.databind.deser.AnySetterTest,tools.jackson.databind.deser.builder.BuilderSimpleTest,tools.jackson.databind.deser.creators.AnySetterForCreator562Test,tools.jackson.databind.introspect.POJOPropertiesCollectorTest test./mvnw -q test./mvnw -q -DskipTests animal-sniffer:checkgit diff --check