-
-
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
ConstructorDetector.USE_PROPERTIES_BASED
does not work with multiple constructors since 2.18
#4860
Comments
@Saljack quick note: please do not omit getters and setters for brevity -- their existence is important wrt property introspection. Reproduction should be faithful to actual use case. |
Actually, I am not sure this should work quite the way that submitter expects. Note, too, that Jackson does not select multiple properties-based constructors; they must resolve into to one. So there is no dynamic choice from In this case it does not seem to matter as the end result is about same. So I guess I do not quite understand why auto-detection works. |
@JooHyukKim plain But support can be added with something like
or But would not be auto-detected. |
Sorry for confusion. Let me try to explain. I use My expectation is that Jackson uses no args constructor if there are multiple constructors and there is no |
@Saljack Ok, good thank you for adding more info -- that's how I think things should actually work. I am not 100% sure why auto-detection kicks in, need to dig deeper. |
Hmmh. Ok, no, for 2.18 this was changed slightly so that an implicit properties-based Creator MAY be detected not just if there's no 0-args constructor but also if In
|
Ok so what I think is specifically needed, to address the failure is this: we can only auto-detect Properties-based Constructor if (and only if) it:
This is being checked for multi-parameter case, but not for 1-parameter. There will still be auto-detection, however; I will not change that -- but in this case without parameter-names module it won't kick in. |
ConstructorDetector.USE_PROPERTIES_BASED
does not work with multiple constructors since 2.18
Thank you for reporting @Saljack ! |
Search before asking
Describe the bug
I have this class:
I use
ConstructorDetector.USE_PROPERTIES_BASED
configuration.Since Jackson 2.18.0 I am no able to deserialize any JSON to this object. It worked in previous versions.
The error is:
It does not deserialize these JSONs
I would expect that it will work at least for
{}
(no args constructor) and{"id": "something"}
(1 arg constructor with the same parameter name).Version Information
2.18.0, 2.18.1 and 2.18.2 is affected
2.17.2 works
Reproduction
<-- Any of the following
-->
Expected behavior
I would expect that it will deserialize JSON instead of throwing an exception.
Additional context
The object for deserialization is an external class and I cannot change it. I can use mixin to override it but I am afraid that this issue can happen with other external objects only if someone adds two constructors.s
The text was updated successfully, but these errors were encountered: