-
-
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
Allow adding of external Object Id resolver #176
Comments
Hi!
Right now is there any way to circumvent this? |
Without having a way to reproduce the issue it is impossible to say what happens. But one possibility is, as exception states, there is unresolved forward reference (current JSON Object references something that is yet to come in stream). Jackson itself makes sure never to produce JSON it could not deserialize (in this regard), but some other packages may shuffle ordering of object properties. Ideally forward references would be resolved, but the issue here is that of keeping track of property accessors (setter/field) of objects; and that would require significant rewrite of internals. I hope this will get done in future, but there is no active work for this (that is, nothing that is known to solve the issue). Above is strictly assuming that the problem is due to reordering of JSON entries: if so, enforcing processing where ordering of JSON Object properties is strictly retained would avoid the issue. |
Could you illustrate with an example when the order of the fields in the JSON impossibilitate Jackson from Deserializing? Thank you. |
How about I will try a definition. Any reference from property earlier in JSON input than the referred object is problematic, with one exception. The exception is that "object id" property of a POJO will always be reordered by Jackson (using buffering if necessary) to be seen as the first property. So this exception can resolve a subset of potential forward-references. |
Thank you. One thing is confusing me, though. Similarly, when the client sends JSON to the server, it only references the id of the object as well. I'm not expecting Jackson to magically deserialize my entire object with only the id. But I would want it to create the object with only the Id assigned or to be able to provide a little helper for Jackson in these situations. Is any of this possible? Basically the main question is: can Jackson deserialize an object with only its id (identity) and nothing else? (Sorry for my persistence. 😄 ) |
Ah yes, that does explain the issue. Use of 'alwaysAsId' assumes that either:
So, no; if full object with id is not serialized, Jackson can not deduce ids automatically. It should be possible to override object id handling on deserialization to figure out id->instance mapping from external sources; but this is not something that has been thought out, or fully designed. But existing end points used by standard functionality can be overridden and modified, and may allow doing that. And now that I read my original description again, yes, the idea with this issue was to investigate how to make this cleanly extensible, supportable. We are always open to ideas, suggestion, code patches! |
Ah, now makes sense. 😄 Thank you for the explanation. I've managed to get the same behavior (outputting only the Id on object relations instead of full object) by writing a custom serializer and deserializer, and then annotating the properties with Thank you! |
Ok good. |
I'm currently in the planning stages of a project that would need to make use of this feature if it were to use jackson. I'm therefore wondering:
|
I can take a look. I'm about done with @JsonUnwrapped support in the xml module, this can be the next thing I tackle. I might even use this feature myself! |
@pgelinas great. This dropped from my radar; I suspect it could be easy to handle. And if need be I can work on that in a week or so -- right now I have bit of fire drill at work, so I have mostly just patched lowest hanging fruits for Jackson. |
I've got a first version going, basically mimics what has been done for generator during serialization. API is very similar, I just need to clean some more and I'll send a PR your way. |
Implemented as per merged PR #401. |
(note: related to #138)
Currently it is assumed that all Object Id resolution is handled internally, using only information available from POJOs to serialize, or coming from JSON to deserialize.
This works acceptably when the default "serialize first instance seen, use ids for rest" handling, but not when trying to deserialize entries when using "always use id", since in latter case JSON itself just does not have actual things being referred.
This should be possible to handle by allowing use of external Object Id resolvers, which would be used if id is not resolvable using JSON content. This object could be called only in cases where it is known to be needed (when resolving references that have "alwaysUseId" marker).
The text was updated successfully, but these errors were encountered: