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

Minor tweak to #4863: "entryStream()" to "propertyStream()" for name unification towards Jackson 3.0 #4871

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Project: jackson-databind
(requested by @nathanukey)
#4849 Not able to deserialize Enum with default typing after upgrading 2.15.4 -> 2.17.1
(reported by Kornel Zemla)
#4863: Add basic Stream support in `JsonNode`: `valueStream()`, `entryStream()`,
#4863: Add basic Stream support in `JsonNode`: `valueStream()`, `propertyStream()`,
`forEachEntry()`

2.18.3 (not yet released)
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/fasterxml/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,14 @@ public Iterator<JsonNode> elements() {
}

/**
* NOTE: This method is deprecated, use {@link #properties()} instead.
*
* @return Iterator that can be used to traverse all key/value pairs for
* object nodes; empty iterator (no contents) for other types
*
* @deprecated As of 2.19, replaced by {@link #properties()}
*/
@Deprecated // since 2.19
public Iterator<Map.Entry<String, JsonNode>> fields() {
return ClassUtil.emptyIterator();
}
Expand All @@ -1030,6 +1035,7 @@ public Iterator<Map.Entry<String, JsonNode>> fields() {
* Accessor that will return properties of {@code ObjectNode}
* similar to how {@link Map#entrySet()} works;
* for other node types will return empty {@link java.util.Set}.
* Replacement for {@link JsonNode#fields()}.
*
* @return Set of properties, if this node is an {@code ObjectNode}
* ({@link JsonNode#isObject()} returns {@code true}); empty
Expand All @@ -1054,24 +1060,26 @@ public Stream<JsonNode> valueStream() {
}

/**
* Returns a stream of all value nodes of this Node, iff
* this node is an an {@code ObjectNode}.
* Returns a stream of all properties (key, value pairs) of this Node,
* iff this node is an an {@code ObjectNode}.
* For other types of nodes, returns empty stream.
*
* @since 2.19
*/
public Stream<Map.Entry<String, JsonNode>> entryStream() {
public Stream<Map.Entry<String, JsonNode>> propertyStream() {
return ClassUtil.emptyStream();
}

/**
* If this node is an {@code ObjectNode}, erforms the given action for each entry
* If this node is an {@code ObjectNode}, performs the given action for each
* property (key, value pair)
* until all entries have been processed or the action throws an exception.
* Exceptions thrown by the action are relayed to the caller.
* For other node types, no action is performed.
*<p>
* Actions are performed in the order of entries, same as order returned by
* Actions are performed in the order of properties, same as order returned by
* method {@link #properties()}.
* This is generally the document order of properties in JSON object.
*
* @param action Action to perform for each entry
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ public JsonNode required(String propertyName) {
/**
* Method to use for accessing all properties (with both names
* and values) of this JSON Object.
*
* @deprecated since 2.19 Use instead {@link #properties()}.
*/
@Deprecated // since 2.19
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
Expand All @@ -338,7 +341,7 @@ public Stream<JsonNode> valueStream() {
}

@Override // @since 2.19
public Stream<Map.Entry<String, JsonNode>> entryStream() {
public Stream<Map.Entry<String, JsonNode>> propertyStream() {
return _children.entrySet().stream();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ public void testStreamMethods()
arr.valueStream().collect(Collectors.toList()));

// And then entryStream() (empty)
assertEquals(0, arr.entryStream().count());
assertEquals(0, arr.propertyStream().count());
assertEquals(Arrays.asList(),
arr.entryStream().collect(Collectors.toList()));
arr.propertyStream().collect(Collectors.toList()));

// And then empty forEachEntry()
arr.forEachEntry((k, v) -> { throw new UnsupportedOperationException(); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void assertNodeNumbers(JsonNode n, int expInt, double expDouble)
protected void assertNonContainerStreamMethods(ValueNode n)
{
assertEquals(0, n.valueStream().count());
assertEquals(0, n.entryStream().count());
assertEquals(0, n.propertyStream().count());

// And then empty forEachEntry()
n.forEachEntry((k, v) -> { throw new UnsupportedOperationException(); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ public void testStreamMethods()
obj.valueStream().collect(Collectors.toList()));

// And then entryStream() (empty)
assertEquals(2, obj.entryStream().count());
assertEquals(2, obj.propertyStream().count());
assertEquals(new ArrayList<>(obj.properties()),
obj.entryStream().collect(Collectors.toList()));
obj.propertyStream().collect(Collectors.toList()));

// And then empty forEachEntry()
final LinkedHashMap<String,JsonNode> map = new LinkedHashMap<>();
Expand Down