@JsonIdentityInfo selective link serialization?

With @JsonIdentityInfo we can do things like:

{ "@id" : 1, "value" : 13, "next" : { "@id" : 2, "value" : 42, "next" : 1 } } 

A link is a primitive type. Is it possible for this link to be serialized as an object? Example:

  { "@id" : 1, "value" : 13, "next" : { "@id" : 2, "value" : 42, "next" : {"$ref":1} } } 

EDIT

useful links

+4
source share
1 answer

You can use the ObjectIdGenerator "generator" property to provide a custom ObjectIdGenerator that handles the creation and binding of object identifiers.

However, the current implementation assumes that the identifier is always a scalar type; either JSON String or Number. Support for JSON objects has been requested, and at least one developer is working on this (to refer to JSOG, similar to what you are trying to do here). You can join the Jackson dev list to discuss this further.

+4
source

Source: https://habr.com/ru/post/1484384/


All Articles