Skip to content

Commit ff29056

Browse files
committed
Fix works in 2.15
1 parent 73d3bbd commit ff29056

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.fasterxml.jackson.databind.node;
2+
3+
4+
import com.fasterxml.jackson.core.JsonParser;
5+
import com.fasterxml.jackson.core.JsonProcessingException;
6+
import com.fasterxml.jackson.databind.JsonNode;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.BeforeEach;
13+
import org.junit.jupiter.api.Test;
14+
15+
public class MissingValues4229Test {
16+
private static final String jsonString =
17+
"{\n"
18+
+ " \"target\": \"target1\"," // Found in <= 2.15.3 and 2.16.0\n
19+
+ " \"object1\": {\n"
20+
+ " \"target\": \"target2\"" // Found in <= 2.15.3, but not in 2.16.0\n
21+
+ " },\n"
22+
+ " \"object2\": {\n"
23+
+ " \"target\": {" // Found in <= 2.15.3, but not in 2.16.0
24+
+ " \"target\": \"ignoredAsParentIsTarget\""
25+
// Expect not to be found (as sub-tree search ends when parent is found)\n
26+
+ " }\n"
27+
+ " }\n"
28+
+ " }";
29+
30+
private JsonNode rootNode;
31+
32+
@BeforeEach
33+
public void init() throws JsonProcessingException {
34+
ObjectMapper objectMapper =
35+
new ObjectMapper().configure(JsonParser.Feature.ALLOW_COMMENTS, true);
36+
rootNode = objectMapper.readTree(jsonString);
37+
}
38+
39+
@Test
40+
public void testFindValues() {
41+
List<JsonNode> foundNodes = rootNode.findValues("target");
42+
43+
List<String> expectedNodePaths = new ArrayList<>();
44+
expectedNodePaths.add("/target");
45+
expectedNodePaths.add("/object1/target");
46+
expectedNodePaths.add("/object2/target");
47+
48+
List<JsonNode> expectedNodes = expectedNodePaths.stream().map(rootNode::at).collect(Collectors.toList());
49+
50+
Assertions.assertEquals(expectedNodes, foundNodes);
51+
}
52+
53+
@Test
54+
public void testFindParents() {
55+
List<JsonNode> foundNodes = rootNode.findParents("target");
56+
57+
List<JsonNode> expectedNodes = new ArrayList<>();
58+
expectedNodes.add(rootNode.at(""));
59+
expectedNodes.add(rootNode.at("/object1"));
60+
expectedNodes.add(rootNode.at("/object2"));
61+
62+
Assertions.assertEquals(expectedNodes, foundNodes);
63+
}
64+
}

0 commit comments

Comments
 (0)