JsonGenerator
supporting JsonIdentityInfo
annotation
#4052
Replies: 2 comments 4 replies
-
I tried the second approach with a custom serializer. The streaming part worked well (in my POJO to be serialized the stream of objects is represented as a typed My assumption was that the outermost serialization invocation would somehow initialize some kind of "transaction context" within which the IDs would be assigned to the objects being serialized and that when the custom serializer would operate within this transaction, it would automatically serialize objects as references, if they had already previously been serialized. |
Beta Was this translation helpful? Give feedback.
-
Just one quick note (alas, I don't have time to dig very deep): none of So, |
Beta Was this translation helpful? Give feedback.
-
I have a long array of objects, where the objects are deeply nested and inter-connected object graphs (also with cycles) and an object owned by one root in the array may also reference objects owned by another root. To make sure objects only get serialized once, I am using Jackson's
@JsonIdentityInfo
annotation which works very nicely.Now, since the array can get very large and is streamed from an external source into memory, I would like to also serialize these objects as a stream, rather than load everything into a
List
and then serialize that. I thought this may be a good use case forJsonGenerator
. When I write the first object usingJsonGenerator#writeObject()
that works nicely, but when I then write the second object, any references to the first object (or an object owned by it) don't get serialized as references. Instead the IDs are reset to 1.So now to my question: Should I:
DefaultSerializerProvider
implementation which increateInstance()
always returns the same instance? (I don't see any way for it to return an instance specific to theJsonGenerator
instance, which makes me think this is not such a good idea.)Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions