JSON Jackson General Links

I have an object that references two other objects

I use Jackson to serialize my objects, but found that my shared object is duplicated, not a link.

The reason is because I understand that Jackson can only be serialized by value, not by reference.

I unsuccessfully inspected some recommended solution.

Any help is appreciated.

current Jackson Lib 1.8.3

+6
source share
2 answers

Well, time passed and Jackson 2.0 came out. Here is the feature requested! I answer this so that people like me recognize it available

https://github.com/FasterXML/jackson-docs/wiki/Presentation-Jackson-2.0

+7
source

Currently (1.9) you will need to write your own serializer, deserializer, to handle this. There is no ready-made support for handling object identity.

Of the Java frameworks, the only thing I know for supporting object identifiers is XStream .

For what it's worth, there is a long-standing feature request for Jackson to add support. And there are reasonable chances that this will work out for 2.0. But even if this happens, it will take some time (a month or two).

UPDATE (April 2013): According to another accepted answer, this function - @JsonIdentityInfo - was indeed included in Jackson 2.0 and is available. No need for custom (de) serializers.

+5
source

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


All Articles