Skip to content

Commit 6729641

Browse files
authored
Backport parts of #4869 in 2.19 (#4874)
1 parent 91fbfa2 commit 6729641

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Project: jackson-databind
4040
`forEachEntry()`
4141
#4867: Add `Optional<JsonNode> JsonNode.asOptional()` convenience method
4242
(fix by Joo-Hyuk K)
43+
#4869: Add `JsonNode.values()` to replace `elements()`
4344

4445
2.18.3 (not yet released)
4546

src/main/java/com/fasterxml/jackson/databind/JsonNode.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -1066,16 +1066,23 @@ public boolean hasNonNull(int index) {
10661066
@Override
10671067
public final Iterator<JsonNode> iterator() { return elements(); }
10681068

1069+
/**
1070+
* Alias for {@link #values()}.
1071+
*/
1072+
public Iterator<JsonNode> elements() {
1073+
return ClassUtil.emptyIterator();
1074+
}
1075+
10691076
/**
10701077
* Method for accessing all value nodes of this Node, iff
10711078
* this node is a JSON Array or Object node. In case of Object node,
10721079
* field names (keys) are not included, only values.
10731080
* For other types of nodes, returns empty iterator.
1074-
* <p>
1075-
* Note: In Jackson 3, this method will be renamed to {@code values()}.
1081+
*
1082+
* @since 2.19
10761083
*/
1077-
public Iterator<JsonNode> elements() {
1078-
return ClassUtil.emptyIterator();
1084+
public Iterator<JsonNode> values() {
1085+
return elements();
10791086
}
10801087

10811088
/**

src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,20 @@ public int size() {
246246
@Override // since 2.10
247247
public boolean isEmpty() { return _children.isEmpty(); }
248248

249+
@Override
250+
public Iterator<JsonNode> elements() {
251+
return _children.listIterator();
252+
}
253+
249254
/**
250255
* {@inheritDoc}
251256
*<p>
252257
* NOTE: actual underlying implementation returns {@link java.util.ListIterator}
253258
* from {@link java.util.List#listIterator()} that contains elements, since Jackson 2.18
254259
* (before was only generic {@link java.util.Iterator}).
255260
*/
256-
@Override
257-
public Iterator<JsonNode> elements() {
261+
@Override // @since 2.19
262+
public Iterator<JsonNode> values() {
258263
return _children.listIterator();
259264
}
260265

src/main/java/com/fasterxml/jackson/databind/node/ObjectNode.java

+5
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ public Iterator<JsonNode> elements() {
275275
return _children.values().iterator();
276276
}
277277

278+
@Override // @since 2.19
279+
public Iterator<JsonNode> values() {
280+
return _children.values().iterator();
281+
}
282+
278283
@Override
279284
public JsonNode get(int index) { return null; }
280285

0 commit comments

Comments
 (0)