-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Consider possibility of allowing "delegating-AND-properties-based" Creators #5084
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
Comments
cc @JooHyukKim |
Sounds like a useful thing to have for users. Can we go further and...
... do this? |
(just like how the title is written, shouldn't this be |
Good point -- either would work but maybe "AND" is better. As long as we use whichever conjunctive consistently. So let's go with "and". @JooHyukKim Yes, start with explicit, see if we can make implicit work for 3.0. |
Filed FasterXML/jackson-annotations#288 for a start. |
Uh oh!
There was an error while loading. Please reload this page.
A recurring use case for value classes is that of wanting to support two related structures for deserialization via Creator methods (constructor / factory method). Basically to allow 2 JSON structures like so:
Initial attempt seems to regularly be to just try single constructor
and hope/expect it works. I think both #2135 and #3210 (just as examples -- there are many more).
This does not work, currently, because Jackson requires every Creator to be of exactly one type: for 1-argument Creators either:
In earlier example, then:
123
works if (and only if) usingmode = Mode.DELEGATING
{"value": 123}
works if (and only if) usingmode = Mode.PROPERTIES
and the trickiest case is one where no
mode
is specified: databind will then try to essentially guess which mode to use -- and this at Deserializer constructor time having only access to Class definition and not JSON value at all (by the time JSON is available, Creators have been long since resolved).So as things are, one MUST define 2 separate Creators: usually one Constructor and one Factory method (one delegating, the other properties based). So like this:
But what if we had theoretical
Mode.DELEGATING_AND_PROPERTIES
, used like this:which would actually support both cases with one Creator?
Internally this could be done by basically constructing 2 Creator entities, but with same actual underlying constructor (or factory method).
In fact, if this works, maybe we could even allow auto-detection? If so, then any 1-parameter Creator that qualifies as Properties-based, could ALSO be detected as Delegating if (and only if) there is no explicitly annotated Delegating creator.
But maybe it is better to consider one step at a time, support explicit "dual-mode".
So, would this be a good idea?
The text was updated successfully, but these errors were encountered: