Skip to content

Commit

Permalink
Fixes to align with [jackson-core#1373] change
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 31, 2024
1 parent aa03d8e commit 80f2c10
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ public boolean isObject() {
public abstract JsonNode path(int index);

@Override
public Iterator<String> propertyNames() {
return ClassUtil.emptyIterator();
public Collection<String> propertyNames() {
return Collections.emptySet();
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/tools/jackson/databind/node/ArrayNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ public JsonNode get(int index) {
}

@Override
public JsonNode get(String fieldName) { return null; }
public JsonNode get(String propertyName) { return null; }

@Override
public Optional<JsonNode> optional(int index) {
return Optional.ofNullable(get(index));
}

@Override
public JsonNode path(String fieldName) { return MissingNode.getInstance(); }
public JsonNode path(String propertyName) { return MissingNode.getInstance(); }

@Override
public JsonNode path(int index) {
Expand Down Expand Up @@ -340,10 +340,10 @@ public void serializeWithType(JsonGenerator g, SerializationContext ctxt, TypeSe
*/

@Override
public JsonNode findValue(String fieldName)
public JsonNode findValue(String propertyName)
{
for (JsonNode node : _children) {
JsonNode value = node.findValue(fieldName);
JsonNode value = node.findValue(propertyName);
if (value != null) {
return value;
}
Expand All @@ -352,28 +352,28 @@ public JsonNode findValue(String fieldName)
}

@Override
public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
public List<JsonNode> findValues(String propertyName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findValues(fieldName, foundSoFar);
foundSoFar = node.findValues(propertyName, foundSoFar);
}
return foundSoFar;
}

@Override
public List<String> findValuesAsText(String fieldName, List<String> foundSoFar)
public List<String> findValuesAsText(String propertyName, List<String> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findValuesAsText(fieldName, foundSoFar);
foundSoFar = node.findValuesAsText(propertyName, foundSoFar);
}
return foundSoFar;
}

@Override
public ObjectNode findParent(String fieldName)
public ObjectNode findParent(String propertyName)
{
for (JsonNode node : _children) {
JsonNode parent = node.findParent(fieldName);
JsonNode parent = node.findParent(propertyName);
if (parent != null) {
return (ObjectNode) parent;
}
Expand All @@ -382,10 +382,10 @@ public ObjectNode findParent(String fieldName)
}

@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
public List<JsonNode> findParents(String propertyName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
foundSoFar = node.findParents(propertyName, foundSoFar);
}
return foundSoFar;
}
Expand Down
72 changes: 36 additions & 36 deletions src/main/java/tools/jackson/databind/node/ObjectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ public Stream<JsonNode> valueStream() {
}

@Override
public Iterator<String> propertyNames() {
return _children.keySet().iterator();
public Collection<String> propertyNames() {
return _children.keySet();
}

@Override
Expand Down Expand Up @@ -635,9 +635,9 @@ public JsonNode replace(String propertyName, JsonNode value)
*
* @return This node after removing property (if any)
*/
public ObjectNode without(String fieldName)
public ObjectNode without(String propertyName)
{
_children.remove(fieldName);
_children.remove(propertyName);
return this;
}

Expand Down Expand Up @@ -850,8 +850,8 @@ public ObjectNode put(String propertyName, short v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Short v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Short v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v.shortValue()));
}

Expand All @@ -864,8 +864,8 @@ public ObjectNode put(String fieldName, Short v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, int v) {
return _put(fieldName, numberNode(v));
public ObjectNode put(String propertyName, int v) {
return _put(propertyName, numberNode(v));
}

/**
Expand All @@ -874,8 +874,8 @@ public ObjectNode put(String fieldName, int v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Integer v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Integer v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v.intValue()));
}

Expand All @@ -888,8 +888,8 @@ public ObjectNode put(String fieldName, Integer v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, long v) {
return _put(fieldName, numberNode(v));
public ObjectNode put(String propertyName, long v) {
return _put(propertyName, numberNode(v));
}

/**
Expand All @@ -904,8 +904,8 @@ public ObjectNode put(String fieldName, long v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Long v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Long v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v.longValue()));
}

Expand All @@ -914,8 +914,8 @@ public ObjectNode put(String fieldName, Long v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, float v) {
return _put(fieldName, numberNode(v));
public ObjectNode put(String propertyName, float v) {
return _put(propertyName, numberNode(v));
}

/**
Expand All @@ -924,8 +924,8 @@ public ObjectNode put(String fieldName, float v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Float v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Float v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v.floatValue()));
}

Expand All @@ -934,8 +934,8 @@ public ObjectNode put(String fieldName, Float v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, double v) {
return _put(fieldName, numberNode(v));
public ObjectNode put(String propertyName, double v) {
return _put(propertyName, numberNode(v));
}

/**
Expand All @@ -944,8 +944,8 @@ public ObjectNode put(String fieldName, double v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Double v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Double v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v.doubleValue()));
}

Expand All @@ -954,8 +954,8 @@ public ObjectNode put(String fieldName, Double v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, BigDecimal v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, BigDecimal v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v));
}

Expand All @@ -964,8 +964,8 @@ public ObjectNode put(String fieldName, BigDecimal v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, BigInteger v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, BigInteger v) {
return _put(propertyName, (v == null) ? nullNode()
: numberNode(v));
}

Expand All @@ -974,8 +974,8 @@ public ObjectNode put(String fieldName, BigInteger v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, String v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, String v) {
return _put(propertyName, (v == null) ? nullNode()
: textNode(v));
}

Expand All @@ -984,8 +984,8 @@ public ObjectNode put(String fieldName, String v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, boolean v) {
return _put(fieldName, booleanNode(v));
public ObjectNode put(String propertyName, boolean v) {
return _put(propertyName, booleanNode(v));
}

/**
Expand All @@ -994,8 +994,8 @@ public ObjectNode put(String fieldName, boolean v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Boolean v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, Boolean v) {
return _put(propertyName, (v == null) ? nullNode()
: booleanNode(v.booleanValue()));
}

Expand All @@ -1004,8 +1004,8 @@ public ObjectNode put(String fieldName, Boolean v) {
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, byte[] v) {
return _put(fieldName, (v == null) ? nullNode()
public ObjectNode put(String propertyName, byte[] v) {
return _put(propertyName, (v == null) ? nullNode()
: binaryNode(v));
}

Expand Down Expand Up @@ -1041,9 +1041,9 @@ public int hashCode() {
/**********************************************************************
*/

protected ObjectNode _put(String fieldName, JsonNode value)
protected ObjectNode _put(String propertyName, JsonNode value)
{
_children.put(fieldName, value);
_children.put(propertyName, value);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void withTree749() throws Exception
ObjectNode ob = (ObjectNode) tree;

JsonNode inner = ob.get("replacements");
String firstFieldName = inner.propertyNames().next();
String firstFieldName = inner.propertyNames().iterator().next();
assertEquals("green", firstFieldName);
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/tools/jackson/databind/node/ArrayNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testDirectCreation() throws Exception
assertStandardEquals(n);
assertFalse(n.values().iterator().hasNext());
assertEquals(0, n.valueSpliterator().estimateSize());
assertFalse(n.propertyNames().hasNext());
assertTrue(n.propertyNames().isEmpty());
assertNotNull(n.propertyNameSpliterator());
assertTrue(n.isEmpty());
TextNode text = TextNode.valueOf("x");
Expand All @@ -47,7 +47,6 @@ public void testDirectCreation() throws Exception
assertNotEquals(0, n.hashCode());
assertTrue(n.values().iterator().hasNext());
// no field names for arrays
assertFalse(n.propertyNames().hasNext());
assertNull(n.get("x")); // not used with arrays
assertTrue(n.path("x").isMissingNode());
assertFalse(n.optional("x").isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testBasicsWithNullNode() throws Exception
assertEquals(0, n.size());
assertTrue(n.isEmpty());
assertTrue(n.values().isEmpty());
assertFalse(n.propertyNames().hasNext());
assertTrue(n.propertyNames().isEmpty());
// path is never null; but does point to missing node
assertNotNull(n.path("xyz"));
assertTrue(n.path("xyz").isMissingNode());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/tools/jackson/databind/node/ObjectNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testBasics()

assertTrue(n.values().isEmpty());
assertTrue(n.properties().isEmpty());
assertFalse(n.propertyNames().hasNext());
assertTrue(n.propertyNames().isEmpty());
assertNull(n.get("a"));
assertFalse(n.optional("a").isPresent());
assertTrue(n.path("a").isMissingNode());
Expand All @@ -155,7 +155,7 @@ public void testBasics()

assertEquals(1, n.size());
assertFalse(n.properties().isEmpty());
assertTrue(n.propertyNames().hasNext());
assertFalse(n.propertyNames().isEmpty());
assertFalse(n.values().isEmpty());
assertSame(text, n.get("a"));
assertSame(text, n.path("a"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testSimple() throws Exception
assertTrue(result.isObject());

ObjectNode main = (ObjectNode) result;
assertEquals("Image", main.propertyNames().next());
assertEquals("Image", main.propertyNames().iterator().next());
JsonNode ob = main.values().iterator().next();
assertType(ob, ObjectNode.class);
ObjectNode imageMap = (ObjectNode) ob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void testCustomEnumInnerMapKey() throws Exception {
JsonNode tree = mapper.convertValue(outerMap, JsonNode.class);

JsonNode innerNode = tree.get("inner");
String key = innerNode.propertyNames().next();
String key = innerNode.propertyNames().iterator().next();
assertEquals("xxxA", key);
}

Expand Down

0 comments on commit 80f2c10

Please sign in to comment.