-
-
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
Deduction deserialization - add support for pojo-hierarchies such that the absence of child fields infers a supertype #3289
Comments
I am not sure whether this is a valid idea, will have to defer to @drekbour. |
Acknowledged, yet to dig and and respond. |
Hi @pakorcz. I refer you to #2976 (comment) and the comments which follow it. The given example (great to see something not involving animals!) makes assumptions on a vanilla usecase that mean it's ok to infer the supertype. Those assumptions will not always hold true and the logic will be chaotic in other configurations. @cowtowncoder Much as it pains me to say, I don't think the change is stable to include. I really opened a can o' worms with this didn't I! We should keep collecting these requirements (I think they are all the same requirement really but expressed in usefully different ways as users try to hack around the limitations) and perhaps they will weave a clearer picture of where a general-case solution can safely add value. I take from this issue the reasonable expectation that supertypes might be ok when they are explicitly included in the set of PS. There exists an alternative implementation of the deduction code which I wrote after the initial PR. It should be faster and would better handle terminal conditions - though nothing can get away from the fact that deser code doesn't why a field is absent given the many options. I'll PR it so it's not lost. |
Yeah I was guessing it would not be something we'd want to do for general usage -- there tends to lots of logic that needs to be added to cover all kinds of cases that "make sense" to one user or use case. +1 for collecting requirements if anyone wants to volunteer -- one possible place would https://github.com/FasterXML/jackson-future-ideas/wiki either new JSTEP-x for "improved deduction", or just another wiki page linked. Ideally I think there should be alternative way to add Type Id detection, given |
I'll raise a new feature because I think I have a workable solution in mind now. It justs needs some meditation before I raise |
Creating an issue as Work-in-Progress sounds reasonable; can always edit/change/close/re-create if need be. |
Thank you guys for explanation and taking an interest in this case! The point of it is exactly what @drekbour wrote: I would really appreciate this feature, because thanks to it – if set of possible json data reflects some kind of hierarchy – then it could be deserialized out of the box to proper class of pojo-hierarchy ( without further mapping and checking of null values). |
👋 I wonder if it would be an option to allow opting in to this behavior by explicitly declaring these disambiguating expectations. (Let me first say that while I've been using Jackson since at least as long as I can remember, I've never ventured out here before so apologies if this idea has already been discussed or is fundamentally broken in some way!) In my understanding the presence of a property is in a natural way a fulfillment of the class CompositePlace extends Place implements WorthSeeing {
@JsonProperty(required = true)
public Map<String, WorthSeeing> places;
}
// or
public CompositePlace(@JsonProperty(value="places", required=true) Map<String, WorthSeeing> places) {...}
// or
record CompositePlace(@JsonProperty(required=true) Map<String, WorthSeeing> places) implements WorthSeeing {} which given I believe that this could be implemented in a quite similar way to what #3290 does:
Thanks for your great work on this amazing library! ❤️ |
Thankyou for thinking through the scenario and code. Honouring |
+1 would love to see this in the next version, can't use the deduction now because the supertypes don't get deducted |
+1 |
I am having the same problem, Is there a solution for it?
|
@rafiulahad Is it possible to share a reproducible test case with your configuration(includin JsonTypeInfo and Mapper) against Jackson 2.15.2 version? It will be easier to provide help 👍🏻👍🏻😄 |
@JooHyukKim, below is a minimal reproducible case using Jackson 2.15.2 test code |
Hi Joo Hyuk,
I included a simple test case in my comment.
Thanks.
-Rafiul
…On Sat, Jun 17, 2023 at 8:04 AM Kim, Joo Hyuk ***@***.***> wrote:
@rafiulahad <https://github.com/rafiulahad> Is it possible to share a
reproducible test case with your configuration(includin JsonTypeInfo and
Mapper) against Jackson 2.15.2 version? It will be easier to provide help
👍🏻👍🏻😄
—
Reply to this email directly, view it on GitHub
<#3289 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFPXVTSGEZ2LWAAQRVPPVTTXLXBQDANCNFSM5FASPSXA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@rafiulahad Please read the whole chain for the current status. There has been no work on this, and I do not that without you or someone working on it anything will happen. Personally I am not sure there should even be lots of more advanced functionality here -- perhaps a better approach would be to allow registering a handler that would be given But that would be a new feature for someone to implement. I do not have time or actual itch to work on this but maybe someone else does. |
I worked around the issue by introducing a field in the super type and not using deduction. |
@rafiulahad Something like that, yes, although whether But the tricky part is how to make it all work with |
The set of classes are the ones mentioned in @JsonSubTypes |
@rafiulahad Yes I was guessing that'd be the case. Note tho that these are typically passed during construction of |
Currently, deduction deserialization requires all values to have unique field. Because of that, there is no way to deserialize values to superclass and subclasses, when
defaultImpl
is different than superclass.Example:
For json:
and pojo-hierarchy:
and deduction deserialization with
defaultImpl
differ then supertype:the
MismatchedInputException
is thrown, because the values with onlyname
fields are not classified toPlace
.Desired behaviour:
UnrecognizedPropertyException
is thrownThe text was updated successfully, but these errors were encountered: