@@ -71,6 +71,33 @@ static class IgnoreUnknown {
71
71
public int a ;
72
72
}
73
73
74
+ @ JsonIgnoreProperties (ignoreUnknown =true )
75
+ static class IgnoreUnknownAnySetter {
76
+
77
+ Map <String , Object > props = new HashMap <>();
78
+
79
+ @ JsonAnySetter
80
+ public void addProperty (String key , Object value ) {
81
+ props .put (key , value );
82
+ }
83
+
84
+ @ JsonAnyGetter
85
+ public Map <String , Object > getProperties () {
86
+ return props ;
87
+ }
88
+ }
89
+
90
+ @ JsonIgnoreProperties (ignoreUnknown =true )
91
+ static class IgnoreUnknownUnwrapped {
92
+
93
+ @ JsonUnwrapped
94
+ UnwrappedChild child ;
95
+
96
+ static class UnwrappedChild {
97
+ public int a , b ;
98
+ }
99
+ }
100
+
74
101
@ SuppressWarnings ("serial" )
75
102
@ JsonIgnoreProperties ({"a" , "d" })
76
103
static class IgnoreMap extends HashMap <String ,Object > { }
@@ -224,6 +251,23 @@ public void testClassWithIgnoreUnknown() throws Exception
224
251
assertEquals (-3 , result .a );
225
252
}
226
253
254
+ public void testAnySetterWithFailOnUnknownDisabled () throws Exception
255
+ {
256
+ final ObjectMapper mapper = MAPPER .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES );
257
+ IgnoreUnknownAnySetter value = mapper .readValue ("{\" x\" :\" y\" , \" a\" :\" b\" }" , IgnoreUnknownAnySetter .class );
258
+ assertNotNull (value );
259
+ assertEquals (2 , value .props .size ());
260
+ }
261
+
262
+ public void testUnwrappedWithFailOnUnknownDisabled () throws Exception
263
+ {
264
+ final ObjectMapper mapper = MAPPER .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES );
265
+ IgnoreUnknownUnwrapped value = mapper .readValue ("{\" a\" :1, \" b\" :2}" , IgnoreUnknownUnwrapped .class );
266
+ assertNotNull (value );
267
+ assertEquals (1 , value .child .a );
268
+ assertEquals (2 , value .child .b );
269
+ }
270
+
227
271
/**
228
272
* Test that verifies that use of {@link JsonIgnore} will add implicit
229
273
* skipping of matching properties.
0 commit comments