Deserializing using a custom type id resolver #371
Unanswered
chavan77me
asked this question in
Q&A
Replies: 1 comment
|
Unfortunately Type id resolvers do not have access to incoming JSON, since parser does not typically have an in-memory representation, but only streaming state (current token; parent path). But this is also a question that an LLM coding tool could probably help with, suggest approaches. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
My json serialization produces an @type field, but I may not have access to the class in my class loader on the deserialization side.
For example, in a hierarchy A->B->C->D, the serialization may use D for the @type field, but on the deserialization, the best I know is probably B. I want to deserialize to B in this case. How can I achieve this?
One thought, I could add a @typeHierarchy field in the json that also lists C->B->A in addition to the @type. If I am able to access the json at the time of type id resolution, I can determine I dont have access to D and C, and therefore B it is. So I thought, if I override TypeIdResolver's typeFromId, use the context to get the parser and look into the json to get the @typeHierarchy field, I can do this (My parser is a json aware parser so I can look at the fields)
The problem I have though is that typeidresolver's typeFromId path is not easy to hook into. what is the right way to offer my own custom typeidresolver? (I dont want to change the default jackson @type resolution, I just want to augment it with information from the json)
All reactions