|
4 | 4 | import java.util.Collections;
|
5 | 5 | import java.util.List;
|
6 | 6 | import java.util.Map;
|
| 7 | +import java.util.Set; |
7 | 8 |
|
8 | 9 | import com.fasterxml.jackson.core.*;
|
9 | 10 |
|
@@ -65,73 +66,6 @@ public void testParserFeatures() throws Exception
|
65 | 66 | verifyException(e, "foo");
|
66 | 67 | }
|
67 | 68 | }
|
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 |
| - } |
135 | 69 |
|
136 | 70 | public void testNodeHandling() throws Exception
|
137 | 71 | {
|
@@ -217,6 +151,108 @@ public void testNoPrefetch() throws Exception
|
217 | 151 | assertEquals(Integer.valueOf(123), n);
|
218 | 152 | }
|
219 | 153 |
|
| 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 | + |
220 | 256 | /*
|
221 | 257 | /**********************************************************
|
222 | 258 | /* Test methods, ObjectCodec
|
|
0 commit comments