-
-
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
ObjectMapper.toJsonNode() Collector Stream Support #4691
ObjectMapper.toJsonNode() Collector Stream Support #4691
Conversation
unit-test in ObjectMapperTest to validate base solution
66004a3
to
4fcaf6f
Compare
I must say I don't quite understand this... need to re-read a few times, maybe I get it. |
You mean my implementation? If so, I can break it down and explain it in a clearer way if you wish. |
Is this use case actually common in the wild? I rarely hold onto JsonNode objects, instead simply deserializing to custom POJO classes. Later I can serialize |
In my use case I don't deserialise JsonNodes because we write the output directly to other processes. Deserialising implies a performance and memory overhead that we can't afford since we are dealing with high data volumes in limited amount of memory. Regardless, having an extra feature which only provides additional support without any side-effects should pose no conflicts to the proposal as a whole, I hope. |
For high-performance within limited memory, you probably want to use jackson's Streaming API rather than |
Thank you for the suggestion, I will for sure look into it, but for now this lib provides the level of abstraction and performance target we are looking for. This proposal only aims at providing an additional support to Streams within the usage example provided above. Is there any technical reason why this method can't be added as an extra layer of support? It would help people like me not have to implement this method every time we import jackson-databind. Thank you for your considerations so far, I do appreciate them truly. |
@rikkarth No, not the implementation but actual usage, need. And my question/comment was not meant as "no" but trying to understand the benefit of addition. |
I think it's useful. Maybe should be called toArrayNode, though. |
Good point. I named it I can rename it if the suggestion is approved. |
* @return a {@link Collector} that collects {@link JsonNode} elements into an {@link ArrayNode} | ||
*/ | ||
public static Collector<JsonNode, ArrayNode, ArrayNode> toJsonNode() { | ||
final JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although for most use the default JsonNodeFactory
is fine, I think it'd better to have a variant that takes in JsonNodeFactory
(or JsonNodeCreator
maybe, which it implements), and then this overload that uses
JsonNodeFactory.instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check now please?
src/test/java/tools/jackson/databind/util/JacksonCollectorsTest.java
Outdated
Show resolved
Hide resolved
@rikkarth Ok, looks good in general, would be happy to merge. But realized 2 things: First, before merging, we'd need a CLA (if you haven't sent one earlier -- one is good for all contributions). It's from https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf and is easiest to print, fill & sign, scan/photo, email to But more important question is this: PR is against |
I will perform a new PR for 2.18 and Thank you. |
Closing in favor of #4709 (which I'll merge forward). |
Context from previous discussion
FasterXML/jackson#239
Description
Based on point #2 (above), I've decided to perform this implementation in the
ObjectMapper
because it was where it made more sense to me. It naturally falls nice into it, since this class is usually used in conjunction with this kind of operations.Usage
Implementation
cc @cowtowncoder