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
Add support for @ConstructorProperties #905
Comments
Sounds like a useful improvement, thank you for suggestion. I wasn't aware of existence of |
Just wanted to let you know I am also looking forward to this feature. |
Support added for 2.7.0. |
Thanks, I'll try it out at least! 👍 |
Official 2.7.0 will take some time, but code is in |
It seems, (in 2.7.3) that the constructorProperties are not correctly parsed when using a custom namingstrategy... still in the progress of figuring out if this is actually the case, but sure looks like it. |
@Athaphian there are two possible interpretations for meaning of
My assumption was that (2) is the proper usage, since this is for |
@cowtowncoder Maybe it can be made configurable as a config option on the mapper? setConstructorPropertiesImplicit or something... and later on ignore the explicitly set constructor properties names? I have not looked at the Jackson code, so don't know if this approach is even possible. |
@Athaphian right, I am thinking along same lines. Could you file a new issue for such a Fwtw, there is already |
Actually, I think that I will make the change for 2.7.4, since this would solve #1122. The only (?) open question would be whether to:
I think I'm ok without (2), but (1) is an open question. |
What would you do about multiple annotated constuctors then? |
@Shredder121 good question. At this point, it'd likely be "throw an exception to indicate ambiguity". One could also consider simple resolution, and perhaps configurable resolution handler. But simplest heuristic would probably be "use one with most parameters". |
That's indeed one heuristic. Maybe with ambiguity require |
This is a recurring concern, and aside from this annotation, also for full auto-detection. |
Yep, same problem here. Using lombok and Jackson suddenly started to use the all-arguments constructor even in the case not all fields are set in the JSON object. This results in the unset fields becoming null which overrides their default values which are set on object level default 👎 |
For anyone else who stumbles upon this - as a result of this change, on upgrading to Jackson 2.7, trying to deserialize a class which is
I started having errors along the following lines:
This is because under the covers Lombok's constructors use the Hope that's useful... |
Thank you @oliverlockwood. Also: it is really important to use latest 2.7 version; currently 2.7.8. There have been many fixes, and at least one directly affects handling of creator properties for static factory methods. |
Any MapperFeature to disable using of ConstructorProperties ? |
Unfortunately, this breaks the
|
@tsabirgaliev If there is a problem, please file a new issue, referencing back to this issue as a root cause. Due to length of discussion it is not easy to see how things fit together. |
@ericxiong Yes, |
This removal happened because of breaking changes in patch versions (projectlombok/lombok#1563) and in the light of potential removal of Lombok from Spring Boot dependencies (spring-projects/spring-boot#12576). Hello data class now implements all the attributes of data class (constructor, getter, equals, hashCode) explicitely. @ConstructorProperties annotation is required for Jackson to be able to create an objects using constructor, see FasterXML/jackson-databind#905
ConstructorProperties provide a standard way to communicate constructor properties. Currently, you have to use
JsonCreator
withJsonProperty
to achieve the same behavior with jackson.Libraries like lombok generate constructors using the standard annotation, which makes it necessary to manually annotate the constructor when using jackson. There are already libraries that add support for this annotation but I believe it could be added to the main project without problems.
I believe ConstructorProperties is absent on android so it might be necessary to handle that gracefully.
The text was updated successfully, but these errors were encountered: