-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
@JsonAnySetter
not working when annotated on both constructor parameter & field
#4634
Comments
Right now, if jackson-databind/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java Lines 669 to 682 in f3c84db
The weird thing is it will then proceed to inject unrecognized properties into NEITHER the field NOR the constructor argument. It works when I reverse the priority/precedence (i.e. allowing constructor parameter to "win"), but I've yet to create a PR to propose for that change because I want to understand what's causing the current bizarre behaviour. |
Ok; with regular accessors there is clearly define precedence so Constructor parameter has precedence over Setter which has precedence over Field. Something similar maybe should probably be done for any-setter (and as necessary any-getter but that's separate), which I think you are suggesting. But as to how injection may fail altogether... I don't know. Does sound weird. |
Actually, now that I bump into the same issue trying to work on #4626, looking at This is why my initial thinking wrt detecting Record Fields in |
Hmmh. Actually, |
Apparently the path for processing
For the case of
|
…h `@JsonAnySetter`, to fix FasterXML#4634.
@JsonAnySetter
not working when annotated on both constructor parameter & field
Yeah, I think I was not a big fan of all plumbing needed to fix #562, but it is a very useful feature. We still have a few other problems left, fwtw. |
Search before asking
Describe the bug
When both a field & constructor parameter has
@JsonAnySetter
, I'm gettingnull
value.I changed the constructor parameter to be assigned to another field to see if maybe the injecting for field vs constructor parameter are overwriting each other e.g.:
...but both
stuffFromField
&stuffFromConstructor
havenull
value.Version Information
2.18.0
Reproduction
Expected behavior
No response
Additional context
While this won't normally happen, it is possible with Records:
@JsonAnySetter
's@Target
allows forElementType.FIELD
&ElementType.PARAMETER
.@JsonAnySetter
is annotated on a Record component, the annotation will be propagated to both field & constructor parameter.@JsonAnySetter
on the constructor parameter.@JsonAnySetter
in both field & constructor parameter, hence this issue.The text was updated successfully, but these errors were encountered: