Skip to content

Commit

Permalink
Post-merge clean up for FasterXML#4229
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 29, 2023
1 parent 1c66e49 commit a0538bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 72 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class TestFindMethods
extends BaseMapTest
{
private final String JSON_SAMPLE = "{ \"a\" : { \"value\" : 3 },"
+"\"array\" : [ { \"b\" : 3 }, {\"value\" : 42}, { \"other\" : true } ]"
+"}";

private final String JSON_4229 = a2q("{"
+ " 'target': 'target1'," // Found in <= 2.15.3 and 2.16.0
+ " 'object1': {"
+ " 'target': 'target2' " // Found in <= 2.15.3, but not in 2.16.0
+ " },"
+ " 'object2': {"
+ " 'target': { " // Found in <= 2.15.3, but not in 2.16.0
+ " 'target': 'ignoredAsParentIsTarget'" // Expect not to be found (as sub-tree search ends when parent is found)
+ " }"
+ " }"
+ "}");

private final ObjectMapper MAPPER = newJsonMapper();

public void testNonMatching() throws Exception
{
JsonNode root = _buildTree();
JsonNode root = MAPPER.readTree(JSON_SAMPLE);

assertNull(root.findValue("boogaboo"));
assertNull(root.findParent("boogaboo"));
Expand All @@ -24,7 +43,7 @@ public void testNonMatching() throws Exception

public void testMatchingSingle() throws Exception
{
JsonNode root = _buildTree();
JsonNode root = MAPPER.readTree(JSON_SAMPLE);

JsonNode node = root.findValue("b");
assertNotNull(node);
Expand All @@ -38,7 +57,7 @@ public void testMatchingSingle() throws Exception

public void testMatchingMultiple() throws Exception
{
JsonNode root = _buildTree();
JsonNode root = MAPPER.readTree(JSON_SAMPLE);

List<JsonNode> nodes = root.findValues("value");
assertEquals(2, nodes.size());
Expand All @@ -61,11 +80,25 @@ public void testMatchingMultiple() throws Exception
assertEquals("42", values.get(1));
}

private JsonNode _buildTree() throws Exception
// [databind#4229]: regression in 2.16.0
public void testFindValues4229() throws Exception
{
final String SAMPLE = "{ \"a\" : { \"value\" : 3 },"
+"\"array\" : [ { \"b\" : 3 }, {\"value\" : 42}, { \"other\" : true } ]"
+"}";
return objectMapper().readTree(SAMPLE);
JsonNode rootNode = MAPPER.readTree(JSON_4229);
assertEquals(Arrays.asList(
rootNode.at("/target"),
rootNode.at("/object1/target"),
rootNode.at("/object2/target")),
rootNode.findValues("target"));
}

// [databind#4229]: regression in 2.16.0
public void testFindParents4229() throws Exception
{
JsonNode rootNode = MAPPER.readTree(JSON_4229);
assertEquals(Arrays.asList(
rootNode,
rootNode.at("/object1"),
rootNode.at("/object2")),
rootNode.findParents("target"));
}
}

0 comments on commit a0538bb

Please sign in to comment.