7

I have an Object that is reference by two other Objects

I use Jackson to serialize my objects but have found my shared object is duplicated rather than reference.

The reason is as I understand that Jackson can only serialize by value and not by reference.

I have unsuccessfully looked around for some recommended solution.

Any and all help is appreciated.

current Jackson Lib 1.8.3

HKalsi
  • 333
  • 3
  • 10

2 Answers2

8

Well time passed and Jackson 2.0 is out. Here is the requested feature ! I answer this so people like me coming after know its available

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

StackHola
  • 914
  • 9
  • 19
5

Currently (1.9) you would have to write custom serializer, deserializer, to handle this. There is no out-of-the-box support for handling object identity.

Of Java frameworks the only one that I know to support object identities is XStream.

For what it is worth, there is a long-standing feature request for Jackson to add support. And there is reasonable chance this gets worked on for 2.0. But even if it will be, it'll take a while (a month or two).

UPDATE (April 2013): As per the other accepted answer, this feature -- @JsonIdentityInfo -- was indeed included in Jackson 2.0, and is available. No need for custom (de)serializers.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • Thank you for the answer, i did see the feature request but was praying that it was a very old one :( . I think i have come up with a workaround, i will be giving my shared object a reference and linking to the reference when i desirialize. Thanks again, much appreciated. – HKalsi Jan 24 '12 at 11:45
  • Yes, old, because it was implemented for 2.0, and has been available since then. I'll update my answer. – StaxMan Apr 22 '13 at 21:04