-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonWriteContext could hold current value. #631
Comments
Interesting thought. I'll have to think about this for a bit, but this might work; I assume it would matter with structured types (i.e. things that come from JSON Object, Array). One practical challenge may be that some datatypes use an alternative Another, possibly bigger challenge is that in some cases current value is known quite late: specifically, when using Creator methods, instance can only be created once all parameters for that are read. Maybe I can play with this and verify there is no measurable performance penalty for added state, update calls. |
One additional comment: earlier I was thinking of storing the current POJO (and perhaps Collection/Map) being handled in
There is also one potential downside -- when constructing temporary readers (from buffered content), access may be compromise -- but that is probably something that can be solved relatively easily. |
Implemented streaming API support as per: and so far no measurable negative performance impact found; so I think this can be added as suggested. I'll add it for both reading and writing, as it is likely to be of some use for both. |
Nice work. Thanks. I don't think i will have time this week to play with the snapshot and give you some feedback already, but i hope next week will be fine. (I'm just using the serializer part for now.) |
No prob: I need to add actual tests myself, to verify handling. I think this is a great addition, thanks once again for suggesting it. I can now also mark another RFE obsolete for databind, since this should cover the intended use case. |
Ok, as per earlier notes, implemented both for |
Better late than never.. :) I think the main missing points comes from the class
I'm not fully sure but it might be easier to implement the setCurrentValue in the As an addon here's my
|
It would be great if we could access the
currentValue
from theJsonWriteContext
. It would give us more flexibility during filtering.In my particular case I have implemented a
BackReferenceAwareBeanSerializer
to be able to break bi-directional relationships. As a side effect I'm also able to break circular references within the path.For this to work the
JsonWriteContext
needs to know thecurrentValue
.Unfortunately the
JsonWriteContext.writeValue
method is final, as well as theUTF8JsonGenerators.writeStartObject/writeStartArray
methods, so I was not able to simply callsetCurrentValue
directly from within these classes. I had to abuse aTypeSerializer
as this one can act as a callback on any write operation.Currently I had to override these classes and it would be great if that could be simplified:
currentValue
attribute)_writeContext
to new context)_createUTF8Generator
andcopy
to use new generator)writePrefix
methods to set currentValue on context)setDefaultTyping
andsetSerializerFactory
)During serialization the
BackReferenceAwareBeanSerializer
walks back up the context hierarchy and compares the pojo with the currentValues and writes the "level" of that as@backReference
.The ObjectIdGenerator feature would not be sufficient here as generated ids are "global". This implementation simply breaks references but continues serializing each path indepentantly.
The text was updated successfully, but these errors were encountered: