4
4
5
5
import com .fasterxml .jackson .databind .BaseMapTest ;
6
6
import com .fasterxml .jackson .databind .JsonNode ;
7
+ import com .fasterxml .jackson .databind .ObjectMapper ;
7
8
8
9
public class TestFindMethods
9
10
extends BaseMapTest
10
11
{
12
+ private final String JSON_SAMPLE = "{ \" a\" : { \" value\" : 3 },"
13
+ +"\" array\" : [ { \" b\" : 3 }, {\" value\" : 42}, { \" other\" : true } ]"
14
+ +"}" ;
15
+
16
+ private final String JSON_4229 = a2q ("{"
17
+ + " 'target': 'target1'," // Found in <= 2.15.3 and 2.16.0
18
+ + " 'object1': {"
19
+ + " 'target': 'target2' " // Found in <= 2.15.3, but not in 2.16.0
20
+ + " },"
21
+ + " 'object2': {"
22
+ + " 'target': { " // Found in <= 2.15.3, but not in 2.16.0
23
+ + " 'target': 'ignoredAsParentIsTarget'" // Expect not to be found (as sub-tree search ends when parent is found)
24
+ + " }"
25
+ + " }"
26
+ + "}" );
27
+
28
+ private final ObjectMapper MAPPER = newJsonMapper ();
29
+
11
30
public void testNonMatching () throws Exception
12
31
{
13
- JsonNode root = _buildTree ( );
32
+ JsonNode root = MAPPER . readTree ( JSON_SAMPLE );
14
33
15
34
assertNull (root .findValue ("boogaboo" ));
16
35
assertNull (root .findParent ("boogaboo" ));
@@ -24,7 +43,7 @@ public void testNonMatching() throws Exception
24
43
25
44
public void testMatchingSingle () throws Exception
26
45
{
27
- JsonNode root = _buildTree ( );
46
+ JsonNode root = MAPPER . readTree ( JSON_SAMPLE );
28
47
29
48
JsonNode node = root .findValue ("b" );
30
49
assertNotNull (node );
@@ -38,7 +57,7 @@ public void testMatchingSingle() throws Exception
38
57
39
58
public void testMatchingMultiple () throws Exception
40
59
{
41
- JsonNode root = _buildTree ( );
60
+ JsonNode root = MAPPER . readTree ( JSON_SAMPLE );
42
61
43
62
List <JsonNode > nodes = root .findValues ("value" );
44
63
assertEquals (2 , nodes .size ());
@@ -61,11 +80,25 @@ public void testMatchingMultiple() throws Exception
61
80
assertEquals ("42" , values .get (1 ));
62
81
}
63
82
64
- private JsonNode _buildTree () throws Exception
83
+ // [databind#4229]: regression in 2.16.0
84
+ public void testFindValues4229 () throws Exception
65
85
{
66
- final String SAMPLE = "{ \" a\" : { \" value\" : 3 },"
67
- +"\" array\" : [ { \" b\" : 3 }, {\" value\" : 42}, { \" other\" : true } ]"
68
- +"}" ;
69
- return objectMapper ().readTree (SAMPLE );
86
+ JsonNode rootNode = MAPPER .readTree (JSON_4229 );
87
+ assertEquals (Arrays .asList (
88
+ rootNode .at ("/target" ),
89
+ rootNode .at ("/object1/target" ),
90
+ rootNode .at ("/object2/target" )),
91
+ rootNode .findValues ("target" ));
92
+ }
93
+
94
+ // [databind#4229]: regression in 2.16.0
95
+ public void testFindParents4229 () throws Exception
96
+ {
97
+ JsonNode rootNode = MAPPER .readTree (JSON_4229 );
98
+ assertEquals (Arrays .asList (
99
+ rootNode ,
100
+ rootNode .at ("/object1" ),
101
+ rootNode .at ("/object2" )),
102
+ rootNode .findParents ("target" ));
70
103
}
71
104
}
0 commit comments