Jackson: @JsonIdentityInfo Object instead of id

Is there a way to influence the serialization process using @JsonIdentityInfo so that it inserts the whole object instead of the id reference?

@Entity
@JsonIdentityInfo(
        generator = ObjectIdGenerators.IntSequenceGenerator.class,
        property = "linkLabel")
public class LinkLabel implements Serializable {
   //...
}

Therefore, instead of referencing "otherObj" with id 1, Jackson must include the entire object.

{
    "objects": [{
            "id": 1,
            "otherObj": [{
                    "id": 1,
                    ...
                }, {
                    "id": 3,
                    ...
                }]
        },
            "id": 2,
            "otherObj": [1] <-- referencing otherObj with id 1
    ]
}

like here:

{
    "objects": [{
            "id": 1,
            "otherObj": [{
                    "id": 1,
                    ...
                }, {
                    "id": 3,
                    ...
                }]
        },
            "id": 2,
            "otherObj": [{
                    "id": 1,  <-- desired format, whole object
                    ...
                }]
    ]
}

We have bi-directional links, so @JsonManagedReference and @JsonBackReference are not working properly. This behavior is described here ( http://wiki.fasterxml.com/JacksonFeatureObjectIdentity ).

+4
source share
2 answers

As stated in the comments and links, @JsonIdentityInfo and Jackson generators do not seem to be able to include object inserts instead of ids.

: Jackson JavaScript, JsonIdentityInfo

, , JSOG, (AngularJS).

+2

, java- JSON. @JsonIdentityInfo , Java JSON, .

JSON Java , JAVA.

, - , . , , , .

- SerializationUtils.serialize/desrialize.

    byte[] bs= SerializationUtils.serialize(classObject);
    ClassObject cloneEntity = (ClassObject ) SerializationUtils.deserialize(bs);

.

0

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


All Articles