Skip to content
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

valueToTree() during serialization (via SerializerProvider()) #2411

Closed
XakepSDK opened this issue Aug 6, 2019 · 6 comments
Closed

valueToTree() during serialization (via SerializerProvider()) #2411

XakepSDK opened this issue Aug 6, 2019 · 6 comments
Labels
3.x most-wanted Tag to indicate that there is heavy user +1'ing action
Milestone

Comments

@XakepSDK
Copy link
Contributor

XakepSDK commented Aug 6, 2019

Currently i have this serializer code:

if(value.hasStyling()) {
    JsonNode jsonNode = JacksonComponentSerializer.MAPPER.valueToTree(value.style());
    if (jsonNode.isObject()) {
        Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
        while (fields.hasNext()) {
            Map.Entry<String, JsonNode> next = fields.next();
            gen.writeFieldName(next.getKey());
            gen.writeTree(next.getValue());
        }
    }
}

Can we have some way to convert object to TreeNode without static access to mapper?

@XakepSDK XakepSDK changed the title valueToTree and treeToValue during serialization valueToTree during serialization Aug 6, 2019
@XakepSDK XakepSDK closed this as completed Aug 6, 2019
@XakepSDK
Copy link
Contributor Author

XakepSDK commented Aug 6, 2019

Still required, as found approach doesn't fit for all serializers, only for some.

@cowtowncoder
Copy link
Member

This is difficult thing to support, since valueToTree() (or conversions in general) are sequences of serialization-then-deserialization, and serialization side does not have support for deserialization (nor is there linkage back to ObjectMapper from serializer).
But I agree that ability to perform such conversions for serialization (and deserialization) is useful.

In short term, a work-around is to use getCodec() method of JsonGenerator that is passed to serialize(): that can be used to call conversion methods.

@cowtowncoder
Copy link
Member

Then again, maybe worth thinking through... since serialization into TokenBuffer is easy and exists, so perhaps it'd be possible to have some sort of short-cut and then applicable without fully configured JsonNode deserializer.

@cowtowncoder cowtowncoder added 2.12 and removed 2.11 labels Apr 12, 2020
@cowtowncoder cowtowncoder added 2.13 most-wanted Tag to indicate that there is heavy user +1'ing action and removed 2.12 labels Oct 27, 2020
@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 1, 2021

Ugggggh. The missing piece for otherwise simple implementation is lack of JsonNodeFactory from SerializerProvider (and SerializationConfig).
So to implement this, would need to solve that problem first.

And, as usual, 3.0 (master) has moved JsonNodeFactory to be accessible from serialization side, so I think I'll just implement this there at first.

@cowtowncoder
Copy link
Member

Hmmh. Ok, while 3.0 does give access to JsonNodeFactory, there is the secondary problem: readTree() used within ObjectMapper does everything by the book, creating DeserializationContext and this does not exist on serialization-only side of things.
And this access to deserialization things is not just a theoretical problem but there is one problem wrt BigDecimal handling, reads; as well as possibility of custom JsonNode (or subtype) deserializers.

One possible way forward would be to have alternative shortcut between JsonNode and TokenBuffer (constructing former from latter, passing in JsonNodeFactory. I'll see if that is doable as that seems reasonable, for now.

@cowtowncoder cowtowncoder added 3.x and removed 2.13 labels Mar 2, 2021
@cowtowncoder cowtowncoder changed the title valueToTree during serialization valueToTree() during serialization (via SerializerProvider()) Mar 2, 2021
@cowtowncoder cowtowncoder added this to the 3.0.0 milestone Mar 3, 2021
cowtowncoder added a commit that referenced this issue Mar 3, 2021
@cowtowncoder
Copy link
Member

Still need to add testing for "embedded" variant (one accessed via SerializerProvider); refactored implementation of valueToTree() in ObjectMapper (and one added in ObjectWriter) are tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x most-wanted Tag to indicate that there is heavy user +1'ing action
Projects
None yet
Development

No branches or pull requests

2 participants