Skip to content

Commit 3d1cb22

Browse files
committed
Add a (now) passing test for #1637; fixed via jackson-core issue 330 (and patch thereof)
1 parent e8c108e commit 3d1cb22

File tree

3 files changed

+110
-67
lines changed

3 files changed

+110
-67
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,8 @@ Patrick Gunia (pgunia@github)
664664
Carsten Wickner (CarstenWickner@github)
665665
* Contributed #1522: Global `@JsonInclude(Include.NON_NULL)` for all properties with a specific type
666666
(2.9.0)
667+
668+
Chris Plummer (strmer15@github)
669+
* Reported #1637: `ObjectReader.at()` with `JsonPointer` stops after first collection
670+
(2.9.0)
671+

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Project: jackson-databind
8787
(requested by Jared J)
8888
#1616: Extraneous type id mapping added for base type itself
8989
#1619: By-pass annotation introspection for array types
90+
#1637: `ObjectReader.at()` with `JsonPointer` stops after first collection
91+
(reported by Chris P)
9092

9193
2.8.9 (not yet released)
9294

src/test/java/com/fasterxml/jackson/databind/ObjectReaderTest.java

Lines changed: 103 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collections;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Set;
78

89
import com.fasterxml.jackson.core.*;
910

@@ -65,73 +66,6 @@ public void testParserFeatures() throws Exception
6566
verifyException(e, "foo");
6667
}
6768
}
68-
69-
public void testNoPointerLoading() throws Exception {
70-
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
71-
72-
JsonNode tree = MAPPER.readTree(source);
73-
JsonNode node = tree.at("/foo/bar/caller");
74-
POJO pojo = MAPPER.treeToValue(node, POJO.class);
75-
assertTrue(pojo.name.containsKey("value"));
76-
assertEquals(1234, pojo.name.get("value"));
77-
}
78-
79-
public void testPointerLoading() throws Exception {
80-
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
81-
82-
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
83-
84-
POJO pojo = reader.readValue(source);
85-
assertTrue(pojo.name.containsKey("value"));
86-
assertEquals(1234, pojo.name.get("value"));
87-
}
88-
89-
public void testPointerLoadingAsJsonNode() throws Exception {
90-
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
91-
92-
ObjectReader reader = MAPPER.readerFor(POJO.class).at(JsonPointer.compile("/foo/bar/caller"));
93-
94-
JsonNode node = reader.readTree(source);
95-
assertTrue(node.has("name"));
96-
assertEquals("{\"value\":1234}", node.get("name").toString());
97-
}
98-
99-
public void testPointerLoadingMappingIteratorOne() throws Exception {
100-
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
101-
102-
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
103-
104-
MappingIterator<POJO> itr = reader.readValues(source);
105-
106-
POJO pojo = itr.next();
107-
108-
assertTrue(pojo.name.containsKey("value"));
109-
assertEquals(1234, pojo.name.get("value"));
110-
assertFalse(itr.hasNext());
111-
itr.close();
112-
}
113-
114-
public void testPointerLoadingMappingIteratorMany() throws Exception {
115-
final String source = "{\"foo\":{\"bar\":{\"caller\":[{\"name\":{\"value\":1234}}, {\"name\":{\"value\":5678}}]}}}";
116-
117-
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
118-
119-
MappingIterator<POJO> itr = reader.readValues(source);
120-
121-
POJO pojo = itr.next();
122-
123-
assertTrue(pojo.name.containsKey("value"));
124-
assertEquals(1234, pojo.name.get("value"));
125-
assertTrue(itr.hasNext());
126-
127-
pojo = itr.next();
128-
129-
assertNotNull(pojo.name);
130-
assertTrue(pojo.name.containsKey("value"));
131-
assertEquals(5678, pojo.name.get("value"));
132-
assertFalse(itr.hasNext());
133-
itr.close();
134-
}
13569

13670
public void testNodeHandling() throws Exception
13771
{
@@ -217,6 +151,108 @@ public void testNoPrefetch() throws Exception
217151
assertEquals(Integer.valueOf(123), n);
218152
}
219153

154+
/*
155+
/**********************************************************
156+
/* Test methods, JsonPointer
157+
/**********************************************************
158+
*/
159+
160+
public void testNoPointerLoading() throws Exception {
161+
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
162+
163+
JsonNode tree = MAPPER.readTree(source);
164+
JsonNode node = tree.at("/foo/bar/caller");
165+
POJO pojo = MAPPER.treeToValue(node, POJO.class);
166+
assertTrue(pojo.name.containsKey("value"));
167+
assertEquals(1234, pojo.name.get("value"));
168+
}
169+
170+
public void testPointerLoading() throws Exception {
171+
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
172+
173+
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
174+
175+
POJO pojo = reader.readValue(source);
176+
assertTrue(pojo.name.containsKey("value"));
177+
assertEquals(1234, pojo.name.get("value"));
178+
}
179+
180+
public void testPointerLoadingAsJsonNode() throws Exception {
181+
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
182+
183+
ObjectReader reader = MAPPER.readerFor(POJO.class).at(JsonPointer.compile("/foo/bar/caller"));
184+
185+
JsonNode node = reader.readTree(source);
186+
assertTrue(node.has("name"));
187+
assertEquals("{\"value\":1234}", node.get("name").toString());
188+
}
189+
190+
public void testPointerLoadingMappingIteratorOne() throws Exception {
191+
final String source = "{\"foo\":{\"bar\":{\"caller\":{\"name\":{\"value\":1234}}}}}";
192+
193+
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
194+
195+
MappingIterator<POJO> itr = reader.readValues(source);
196+
197+
POJO pojo = itr.next();
198+
199+
assertTrue(pojo.name.containsKey("value"));
200+
assertEquals(1234, pojo.name.get("value"));
201+
assertFalse(itr.hasNext());
202+
itr.close();
203+
}
204+
205+
public void testPointerLoadingMappingIteratorMany() throws Exception {
206+
final String source = "{\"foo\":{\"bar\":{\"caller\":[{\"name\":{\"value\":1234}}, {\"name\":{\"value\":5678}}]}}}";
207+
208+
ObjectReader reader = MAPPER.readerFor(POJO.class).at("/foo/bar/caller");
209+
210+
MappingIterator<POJO> itr = reader.readValues(source);
211+
212+
POJO pojo = itr.next();
213+
214+
assertTrue(pojo.name.containsKey("value"));
215+
assertEquals(1234, pojo.name.get("value"));
216+
assertTrue(itr.hasNext());
217+
218+
pojo = itr.next();
219+
220+
assertNotNull(pojo.name);
221+
assertTrue(pojo.name.containsKey("value"));
222+
assertEquals(5678, pojo.name.get("value"));
223+
assertFalse(itr.hasNext());
224+
itr.close();
225+
}
226+
227+
// [databind#1637]
228+
public void testPointerWithArrays() throws Exception
229+
{
230+
final String json = aposToQuotes("{\n'wrapper1': {\n" +
231+
" 'set1': ['one', 'two', 'three'],\n" +
232+
" 'set2': ['four', 'five', 'six']\n" +
233+
"},\n" +
234+
"'wrapper2': {\n" +
235+
" 'set1': ['one', 'two', 'three'],\n" +
236+
" 'set2': ['four', 'five', 'six']\n" +
237+
"}\n}");
238+
239+
final Pojo1637 testObject = MAPPER.readerFor(Pojo1637.class)
240+
.at("/wrapper1")
241+
.readValue(json);
242+
assertNotNull(testObject);
243+
244+
assertNotNull(testObject.set1);
245+
assertTrue(!testObject.set1.isEmpty());
246+
247+
assertNotNull(testObject.set2);
248+
assertTrue(!testObject.set2.isEmpty());
249+
}
250+
251+
public static class Pojo1637 {
252+
public Set<String> set1;
253+
public Set<String> set2;
254+
}
255+
220256
/*
221257
/**********************************************************
222258
/* Test methods, ObjectCodec

0 commit comments

Comments
 (0)