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 basic Stream support in JsonNode: valueStream(), propertyStream(), forEachEntry() #4863

Closed
cowtowncoder opened this issue Dec 22, 2024 · 1 comment
Assignees
Labels
2.19 Issues planned at 2.19 or later
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Dec 22, 2024

(note: part of JSTEP-3 work)

Currently use of Tree Model with Java 8 Streams is bit more complicated than necessary, since there are no java.util.stream.Stream producing methods in JsonNode. But it should be straight-forward at methods as follows:

  1. Stream<JsonNode> JsonNode.valueStream(): for ArrayNode return Stream of all element JsonNodes; for ObjectNode return Stream of all values of child entries; for other nodes empty Stream
  2. Stream<Map.Entry> JsonNode.propertyStream(): for ObjectNode return Stream of all properties (name, value pairs); for other nodes empty Stream
  3. void JsonNode.forEachEntry(BiConsumer<String, JsonNode>): for ObjectNode calls consumer with all entries; for other nodes does nothing.

In future we could also consider some of:

  • "parallel" stream variants (for valueStream(), propertyStream())
  • "spliterator" for value/property streams

But let's start with the simplest cases first.

@cowtowncoder cowtowncoder added the 2.19 Issues planned at 2.19 or later label Dec 22, 2024
@cowtowncoder cowtowncoder self-assigned this Dec 22, 2024
@cowtowncoder cowtowncoder added this to the 2.19.0 milestone Dec 23, 2024
@cowtowncoder cowtowncoder changed the title Add basic Stream support in JsonNode: valueStream(), entryStream(), forEachEntry() Add basic Stream support in JsonNode: valueStream(), propertyStream(), forEachEntry() Dec 28, 2024
@cowtowncoder
Copy link
Member Author

cowtowncoder commented Dec 28, 2024

NOTE: renamed entryStream -> propertyStream as per naming guidance of JSTEP-6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.19 Issues planned at 2.19 or later
Projects
None yet
Development

No branches or pull requests

1 participant