On Fri, Nov 10, 2017 at 4:10 AM, Dawid Weiss <[email protected]> wrote: > > Hello, > > We have a scenario where we have multiple references (across the serialized > hierarchy) to a class we don't have direct control over. This class > currently uses a custom serializer/ deserializer combo, but we'd also like > to use references so that the same instance is serialized/ recreated once > from a JSON file. > > We added a mixin with: > > @JsonIdentityInfo(generator = UUIDGenerator.class, property="_ref") > > but this doesn't seem to work when combined with a custom serializer -- all > references to the same instance are serialized fully). Jackson 2.8.9. Any > idea what we do wrong or how this can be achieved?
Unfortunately reading/writing Object Id values, references, requires support by value (de)serializers and is not (and can not be) supported externally by Jackson. In fact Object references only work for POJOs at this point. Collection and Map handlers participate in handling of (POJO) values. Other types are mostly value types where value of references seems more limited. This does not mean that custom types could not support object identity, but if they do, they have to implement much of handling. Basically what is needed is finding annotations (via AnnotationIntrospector.findObjectIdInfo()), most likely from `createContextual()` (of `ContextualSerializer` / `ContextualDeserializer` that custom handlers may implement). I don't remember if custom handling is tested (although don't see any obvious test classes under `src/test/com/fasterxml/jackson/databind/objectid`). But I don't why it should not be possible. I don't know if doing that is practical. If you or anyone wants to try it I can help but I don't think this has come up earlier. -+ Tatu +- > > -- > You received this message because you are subscribed to the Google Groups > "jackson-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
