Skip to content

Commit

Permalink
Minor tweak to #4836: "entryStream()" to "propertyStream()" wrt goal …
Browse files Browse the repository at this point in the history
…of aligning naming.

Also deprecate `JsonNode.fields()` method
  • Loading branch information
cowtowncoder committed Dec 28, 2024
1 parent a7cf2f3 commit 266e68f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
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 @@ -338,7 +338,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

0 comments on commit 266e68f

Please sign in to comment.