1010import tools .jackson .databind .testutil .DatabindTestUtil ;
1111import tools .jackson .databind .testutil .failure .JacksonTestFailureExpected ;
1212
13+ import static org .junit .jupiter .api .Assertions .assertEquals ;
1314import static org .junit .jupiter .api .Assertions .fail ;
1415
1516class UnwrappedWithUnknown650Test extends DatabindTestUtil {
@@ -22,20 +23,27 @@ static class B {
2223 public String field ;
2324 }
2425
25-
26+ private final ObjectMapper MAPPER = JsonMapper .builder ()
27+ .enable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
28+ .build ();
29+
2630 @ JacksonTestFailureExpected
2731 @ Test
2832 void failOnUnknownPropertyUnwrapped () throws Exception {
29- final ObjectMapper mapper = JsonMapper .builder ()
30- .enable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
31- .build ();
3233
33- final String JSON = "{'field': 'value', 'bad':'bad value'}" ;
34+ final String JSON = "{'field': 'value', 'bad': 'bad value'}" ;
3435 try {
35- mapper .readValue (a2q (JSON ), A .class );
36+ MAPPER .readValue (a2q (JSON ), A .class );
3637 fail ("Exception was not thrown on unknown property" );
3738 } catch (UnrecognizedPropertyException e ) {
3839 verifyException (e , "Unrecognized property" );
3940 }
4041 }
42+
43+ // Passing case, regular usage
44+ @ Test
45+ void worksOnRegularPropertyUnwrapped () throws Exception {
46+ A value = MAPPER .readValue (a2q ("{'field': 'value'}" ), A .class );
47+ assertEquals ("value" , value .b .field );
48+ }
4149}
0 commit comments