Skip to content

Commit 21a11f4

Browse files
authored
Fix regression in ObjectNode.with() (#5099)
1 parent 3ff375f commit 21a11f4

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1930,3 +1930,7 @@ Joren Inghelbrecht (@jin-harmoney)
19301930
Will Paul (@dropofwill)
19311931
* Contributed #4979: Allow default enums with `@JsonCreator`
19321932
(2.19.0)
1933+
1934+
Ryan Schmitt (@rschmitt)
1935+
* Contributed #5099: Fix regression in `ObjectNode.with()`
1936+
(2.19.0)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public ObjectNode with(String exprOrProperty) {
8787
.getClass().getName() + "`)");
8888
}
8989
ObjectNode result = objectNode();
90-
return _put(exprOrProperty, result);
90+
_put(exprOrProperty, result);
91+
return result;
9192
}
9293

9394
@Override

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ public void testNullKeyChecking()
291291

292292
assertThrows(NullPointerException.class, () -> src.set(null, BooleanNode.TRUE));
293293
assertThrows(NullPointerException.class, () -> src.replace(null, BooleanNode.TRUE));
294-
294+
295295
assertThrows(NullPointerException.class, () -> src.setAll(Collections.singletonMap(null,
296296
MAPPER.createArrayNode())));
297297
}
298-
298+
299299
@Test
300300
public void testRemove()
301301
{
@@ -334,6 +334,25 @@ public void testValidWithObject() throws Exception
334334
assertEquals("{\"prop\":{}}", MAPPER.writeValueAsString(root));
335335
}
336336

337+
// for [databind#5099]
338+
@Test
339+
public void testValidWith() throws Exception
340+
{
341+
ObjectNode root = MAPPER.createObjectNode();
342+
assertEquals("{}", MAPPER.writeValueAsString(root));
343+
344+
@SuppressWarnings("deprecation")
345+
ObjectNode withResult = root.with( "with" );
346+
withResult.put( "key", "value" );
347+
348+
ObjectNode withObjectResult = root.withObject( "withObject" );
349+
withObjectResult.put( "key", "value" );
350+
351+
assertEquals("{\"key\":\"value\"}", MAPPER.writeValueAsString(withObjectResult));
352+
assertEquals("{\"key\":\"value\"}", MAPPER.writeValueAsString(withResult));
353+
assertEquals(withResult, withObjectResult);
354+
}
355+
337356
@Test
338357
public void testValidWithArray() throws Exception
339358
{

0 commit comments

Comments
 (0)