-
-
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
Incompatible FAIL_ON_MISSING_PRIMITIVE_PROPERTIES
and field level @JsonProperty
#2977
Comments
Thank you for reporting this issue: I will try to figure this out before 2.12.1 patch release. |
Hmmmh. So, the problem here is that the field and constructor parameter are not linked, so that intended/implied relationship (to effectively rename constructor parameter as "aa") does not happen and it is considered to just be The reason for missing linkage gets bit complicated but it is a limitation of the way Creator methods are discovered too late to be linked with other accessors UNLESS constructor parameters are explicitly annotated. Work-around that should work here is to annotate constructor parameter with I plan to add a reproduction under |
This seems strange since it's working if not using a primitive type for the field. Perhaps it's something much simpler and easier to fix? |
@GeorgiPetkov that makes sense since But while this prevents exception, it will not change the fact that field is used, not constructor. Interestingly enough |
Reopening the issue, I closed it by accident. @cowtowncoder If I understand correctly @cowtowncoder AFAIK the Meanwhile for other people that may encounter this and if you're using Lombok already you can simply use the following property to avoid the necessity of any changes in your code before/after the fix:
|
@GeorgiPetkov No the problem is that:
In addition there is field Now: normally there should be association between field and constructor parameter, as their implicit names match: and after this linkage exist, they are part of a single logical property and that property would get renamed as This linkage, in turn, is missing because fields, methods, and name-annotated constructor parameters are introspected by This does give me an idea, however, regarding possibly (fingers crossed) finding linkage via implicit name, in addition to explicit name (explicit meaning "defined by annotation" and implicit "name derived from field/method name in bytecode"). |
@cowtowncoder Seems like I'm doing a really great job as a rubber duck 🤞 |
... ok some minor further developments. Reproducing the issue, I can verify 2 main work-arounds (one that Lombok would use I think):
I also noticed that one part of validation for |
Ok. So, looks like As to "can not map null": problem is indeed that failure is detected in |
FAIL_ON_MISSING_PRIMITIVE_PROPERTIES
and field level @JsonProperty
Describe the bug
The FAIL_ON_MISSING_PRIMITIVE_PROPERTIES is not working properly with field level @JsonProperty annotation. The @JsonProperty annotation is simply ignored.
Version information
Currently latest 2.12, Java 15.0.1
To Reproduce
If you have a way to reproduce this with:
The issue seems to be unrelated to the fact that I use a single argument constructor, I used single property for simlicity in the test. In other words, the new
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
appears to be irrelevant for this bug.Expected behavior
The FAIL_ON_MISSING_PRIMITIVE_PROPERTIES feature should be aware of property names mapping through @JsonProperty when used on fields.
The text was updated successfully, but these errors were encountered: