|
4 | 4 |
|
5 | 5 | import com.fasterxml.jackson.annotation.JsonAnySetter;
|
6 | 6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
| 7 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
7 | 8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
8 | 9 | import com.fasterxml.jackson.annotation.JsonSetter;
|
9 | 10 | import com.fasterxml.jackson.core.JsonProcessingException;
|
@@ -302,19 +303,46 @@ public ValueClass822(int x, Map<String,Object> stuff) {
|
302 | 303 | */
|
303 | 304 |
|
304 | 305 | private final ObjectMapper MAPPER = new ObjectMapper();
|
305 |
| - |
| 306 | + |
306 | 307 | public void testSimple() throws Exception
|
307 | 308 | {
|
308 | 309 | String json = "{\"x\":1,\"y\":2}";
|
309 | 310 | Object o = MAPPER.readValue(json, ValueClassXY.class);
|
310 | 311 | assertNotNull(o);
|
311 |
| - assertSame(ValueClassXY.class, o.getClass()); |
312 |
| - ValueClassXY value = (ValueClassXY) o; |
313 |
| - // note: ctor adds one to both values |
314 |
| - assertEquals(value._x, 2); |
315 |
| - assertEquals(value._y, 3); |
| 312 | + assertSame(ValueClassXY.class, o.getClass()); |
| 313 | + ValueClassXY value = (ValueClassXY) o; |
| 314 | + // note: ctor adds one to both values |
| 315 | + assertEquals(value._x, 2); |
| 316 | + assertEquals(value._y, 3); |
316 | 317 | }
|
317 | 318 |
|
| 319 | + // related to [databind#1214] |
| 320 | + public void testSimpleWithIgnores() throws Exception |
| 321 | + { |
| 322 | + // 'z' is unknown, and would fail by default: |
| 323 | + String json = "{\"x\":1,\"y\":2,\"z\":3}"; |
| 324 | + Object o = null; |
| 325 | + |
| 326 | + try { |
| 327 | + o = MAPPER.readValue(json, ValueClassXY.class); |
| 328 | + fail("Should not pass"); |
| 329 | + } catch (JsonMappingException e) { |
| 330 | + verifyException(e, "Unrecognized field \"z\""); |
| 331 | + } |
| 332 | + |
| 333 | + // but with config overrides should pass |
| 334 | + ObjectMapper ignorantMapper = new ObjectMapper(); |
| 335 | + ignorantMapper.configOverride(SimpleBuilderXY.class) |
| 336 | + .setIgnorals(JsonIgnoreProperties.Value.forIgnoreUnknown(true)); |
| 337 | + o = ignorantMapper.readValue(json, ValueClassXY.class); |
| 338 | + assertNotNull(o); |
| 339 | + assertSame(ValueClassXY.class, o.getClass()); |
| 340 | + ValueClassXY value = (ValueClassXY) o; |
| 341 | + // note: ctor adds one to both values |
| 342 | + assertEquals(value._x, 2); |
| 343 | + assertEquals(value._y, 3); |
| 344 | + } |
| 345 | + |
318 | 346 | public void testMultiAccess() throws Exception
|
319 | 347 | {
|
320 | 348 | String json = "{\"c\":3,\"a\":2,\"b\":-9}";
|
|
0 commit comments