Skip to content

Commit ae38732

Browse files
committed
Fix #3535
1 parent c106d97 commit ae38732

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Project: jackson-databind
4545
from parser nor use real defaults
4646
#3530: Change LRUMap to just evict one entry when maxEntries reached
4747
(contributed by @pjfanning)
48+
#3535: Replace `JsonNode.with()` with `JsonNode.withObject()`
4849

4950
2.13.4 (not yet released)
5051

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1084,23 +1084,27 @@ public final List<JsonNode> findParents(String fieldName)
10841084
* If the node method is called on is not Object node,
10851085
* or if property exists and has value that is not Object node,
10861086
* {@link UnsupportedOperationException} is thrown
1087-
*<p>
1088-
* NOTE: since 2.10 has had co-variant return type
10891087
*/
1090-
public <T extends JsonNode> T with(String propertyName) {
1088+
public <T extends JsonNode> T withObject(String propertyName) {
10911089
throw new UnsupportedOperationException("JsonNode not of type ObjectNode (but "
10921090
+getClass().getName()+"), cannot call with() on it");
10931091
}
10941092

1093+
/**
1094+
* @deprecated Since 2.14 use {@code withObject} instead
1095+
*/
1096+
@Deprecated // since 2.14
1097+
public final <T extends JsonNode> T with(String propertyName) {
1098+
return withObject(propertyName);
1099+
}
1100+
10951101
/**
10961102
* Method that can be called on Object nodes, to access a property
10971103
* that has <code>Array</code> value; or if no such property exists, to create,
10981104
* add and return such Array node.
10991105
* If the node method is called on is not Object node,
11001106
* or if property exists and has value that is not Array node,
11011107
* {@link UnsupportedOperationException} is thrown
1102-
*<p>
1103-
* NOTE: since 2.10 has had co-variant return type
11041108
*/
11051109
public <T extends JsonNode> T withArray(String propertyName) {
11061110
throw new UnsupportedOperationException("JsonNode not of type ObjectNode (but "

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public Iterator<Map.Entry<String, JsonNode>> fields() {
150150

151151
@SuppressWarnings("unchecked")
152152
@Override
153-
public ObjectNode with(String propertyName) {
153+
public ObjectNode withObject(String propertyName) {
154154
JsonNode n = _children.get(propertyName);
155155
if (n != null) {
156156
if (n instanceof ObjectNode) {

src/test/java/com/fasterxml/jackson/databind/node/NodeJDKSerializationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void testObjectNodeSerialization() throws Exception
2525
root.put("answer", 42);
2626
ArrayNode arr = root.withArray("matrix");
2727
arr.add(1).add(12345678901L).add(true).add("...");
28-
ObjectNode misc = root.with("misc");
28+
ObjectNode misc = root.withObject("misc");
2929
misc.put("value", 0.25);
3030

3131
testNodeRoundtrip(root);

src/test/java/com/fasterxml/jackson/databind/node/ObjectNodeTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void testValidWith() throws Exception
303303
{
304304
ObjectNode root = MAPPER.createObjectNode();
305305
assertEquals("{}", MAPPER.writeValueAsString(root));
306-
JsonNode child = root.with("prop");
306+
JsonNode child = root.withObject("prop");
307307
assertTrue(child instanceof ObjectNode);
308308
assertEquals("{\"prop\":{}}", MAPPER.writeValueAsString(root));
309309
}
@@ -321,7 +321,7 @@ public void testInvalidWith() throws Exception
321321
{
322322
JsonNode root = MAPPER.createArrayNode();
323323
try { // should not work for non-ObjectNode nodes:
324-
root.with("prop");
324+
root.withObject("prop");
325325
fail("Expected exception");
326326
} catch (UnsupportedOperationException e) {
327327
verifyException(e, "not of type ObjectNode");
@@ -330,7 +330,7 @@ public void testInvalidWith() throws Exception
330330
ObjectNode root2 = MAPPER.createObjectNode();
331331
root2.put("prop", 13);
332332
try { // should not work for non-ObjectNode nodes:
333-
root2.with("prop");
333+
root2.withObject("prop");
334334
fail("Expected exception");
335335
} catch (UnsupportedOperationException e) {
336336
verifyException(e, "has value that is not");

0 commit comments

Comments
 (0)