Skip to content

Add basic Stream support in JsonNode: valueStream(), propertyStream(), forEachEntry() #4863

@cowtowncoder

Description

@cowtowncoder

(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.

Metadata

Metadata

Assignees

Labels

2.19Issues planned at 2.19 or later

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions