Use and effects of @JsonIdentityInfo for recursive json schema definitions #311
Replies: 2 comments 16 replies
-
|
Without knowing full details/intents I could be wrong, but I think use of Also quick note on "in practice": that's clumsy way of saying "this is how Jackson implements it" (but implying other implementations could produce output that is not necessarily ordered this way). |
Beta Was this translation helpful? Give feedback.
-
|
@cowtowncoder I've just discovered the JavaScript Object Graph project: https://github.com/jsog/jsog Interestingly, it has a Jackson plugin implementation https://github.com/jsog/jsog-jackson that uses the @JsonIdentityInfo generator property to customize the generator. I'm looking over this code myself, but wanted to make you aware of it's existence too. Looks like it was produced a while ago, so I'm hoping it still functions as described with recent Jackson. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm a little new to the Jackson API, although very experienced in Java.
I'm working on a proposal for adding Groups to the MCP protocol. The mcp-java-sdk uses Jackson (2.19.something I think).
In the Groups proposal I've suggested introducing a nested Group structure, by adding a 'parent' Group attribute. This provides for arbitrary hierarchy of groups.
With normal serialization/deserialization of json with this schema the Group.parent recursive/nested structure could produce a lot of duplication of groups (for example if the same nested hierarchy of Groups was assigned to multiple Tools).
I've heard that the @JsonIdentityInfo annotation can be used for this situation, to replace all but the first given Group instance with a json reference, so that on deserialization the Group tree structure is reconstituted by clients.
I've read the docs for @JsonIdentityInfo and it says this:
...In practice this is done by serializing the first instance as full object and object identity, and other references to the object as reference values....
My question is: Is adding @JsonIdentityInfo to the Group type...e.g. here all that's necessary to get this 'in practice' behavior? (i.e. serialize to json the first reference to a given Group, and send a json reference for all other references?). Or are there other options required for getting this in practice behavior (and/or changing/customizing that behavior)?
Beta Was this translation helpful? Give feedback.
All reactions