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

Add JacksonCollectors with toArrayNode() implementation #4709

Merged

Conversation

rikkarth
Copy link
Contributor

@rikkarth rikkarth commented Sep 20, 2024

See back reference: #4691

cc @cowtowncoder

@cowtowncoder
Copy link
Member

Looks good overall, CLA seems to be sent.

One last thing: I do think name toArrayNode() would make sense, given this is what is result of collection. So let's make that one change.

@rikkarth
Copy link
Contributor Author

rikkarth commented Sep 20, 2024

Looks good overall, CLA seems to be sent.

One last thing: I do think name toArrayNode() would make sense, given this is what is result of collection. So let's make that one change.

Done as instructed. Thank you.

(force pushes just to clean up the commit messages)

@rikkarth rikkarth force-pushed the feat/JacksonCollectorStreamSupport branch from 0c3d91f to 156aa73 Compare September 20, 2024 17:55
@rikkarth rikkarth force-pushed the feat/JacksonCollectorStreamSupport branch from 156aa73 to 006e43a Compare September 20, 2024 17:58
@rikkarth
Copy link
Contributor Author

Just for future reference future Stream support implementations may include all types of object.

Example

// don't mind the signature name
// notice the return has changed from JsonNode to String
public static Collector<String, ArrayNode, ArrayNode> someNewSignature(JsonNodeCreator nodeCreator) {
    return Collector.of(
            nodeCreator::arrayNode, // supplier
            ArrayNode::add, // accumulator <---- every type supported by add can become a collector implementation now
            ArrayNode::addAll // combiner
        );
}

Use-Case

@Test
public void testToArrayNsode()
{
    final ObjectMapper objectMapper = new ObjectMapper();

    final JsonNode jsonNodeResult = IntStream.range(0, 10)
        .mapToObj(i -> "Hello")
        .collect(JacksonCollectors.toArrayNodeString());

    System.out.println(jsonNodeResult);
}

Output

["Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello", "Hello"]

@cowtowncoder cowtowncoder changed the title JacksonCollectors.toJsonNode implementation Add JacksonCollectors with toArrayNode() implementation Sep 20, 2024
@cowtowncoder cowtowncoder merged commit 567e089 into FasterXML:2.18 Sep 20, 2024
9 checks passed
@cowtowncoder
Copy link
Member

Merged: thank you for contributing this, @rikkarth ! Will be in 2.18.0, to be released within week or so.

@rikkarth
Copy link
Contributor Author

Merged: thank you for contributing this, @rikkarth ! Will be in 2.18.0, to be released within week or so.

Thank you, you were very supportive and nice, I really appreciate it. I intend to continue supporting you in the future.

@cowtowncoder
Copy link
Member

Glad this worked out very well; looking forward to our future collaboration @rikkarth !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants