diff --git a/release-notes/VERSION b/release-notes/VERSION index d06d2e8c6a..6144851a24 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -7,6 +7,8 @@ Versions: 3.x (for earlier see VERSION-2.x) 3.0.0 (not yet released) +#493: Change `DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES` default to `false` + (contributed by Joo-Hyuk K) #1058: Add a way to pass std and format-specific parser/generator flags during parser/generation construction #1600: Serializing locale with underscore, not standard hyphen diff --git a/src/main/java/tools/jackson/databind/DeserializationFeature.java b/src/main/java/tools/jackson/databind/DeserializationFeature.java index 164cf58f97..5d37068e29 100644 --- a/src/main/java/tools/jackson/databind/DeserializationFeature.java +++ b/src/main/java/tools/jackson/databind/DeserializationFeature.java @@ -110,12 +110,12 @@ public enum DeserializationFeature implements ConfigFeature * This setting only takes effect after all other handling * methods for unknown properties have been tried, and * property remains unhandled. + * Enabling this feature means that a {@link DatabindException} + * will be thrown if an unknown property is encountered. *

- * Feature is enabled by default (meaning that a - * {@link DatabindException} will be thrown if an unknown property - * is encountered). + * Feature is disabled by default as of Jackson 3.0 (in 2.x it was enabled). */ - FAIL_ON_UNKNOWN_PROPERTIES(true), + FAIL_ON_UNKNOWN_PROPERTIES(false), /** * Feature that determines whether encountering of JSON null diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorsTest.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorsTest.java index c8dc102cb5..0dfbb09f23 100644 --- a/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorsTest.java +++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordCreatorsTest.java @@ -43,7 +43,7 @@ public String getValue() { public String accessValueForTest() { return value; } } - private final ObjectMapper MAPPER = newJsonMapper(); + private final ObjectMapper MAPPER = jsonMapperBuilder().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); /* /********************************************************************** diff --git a/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java b/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java index 1f176ccfb4..8d0ce9f689 100644 --- a/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java +++ b/src/test-jdk17/java/tools/jackson/databind/records/RecordExplicitCreatorsTest.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import tools.jackson.databind.DatabindException; +import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.MapperFeature; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.InvalidDefinitionException; @@ -106,6 +107,7 @@ public static RecordWithExplicitFactoryMethod valueOf(String value) { private final ObjectMapper MAPPER = jsonMapperBuilder() .disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) // So that test cases don't have to assert weird error messages + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .build(); /* diff --git a/src/test/java/tools/jackson/databind/deser/AnySetterTest.java b/src/test/java/tools/jackson/databind/deser/AnySetterTest.java index 9264aab4b8..7621b513f0 100644 --- a/src/test/java/tools/jackson/databind/deser/AnySetterTest.java +++ b/src/test/java/tools/jackson/databind/deser/AnySetterTest.java @@ -301,8 +301,9 @@ public void testSimpleMapImitation() throws Exception public void testAnySetterDisable() throws Exception { try { - MAPPER.readValue(a2q("{'value':3}"), - MapImitatorDisabled.class); + MAPPER.readerFor(MapImitatorDisabled.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(a2q("{'value':3}")); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized property \"value\""); diff --git a/src/test/java/tools/jackson/databind/deser/IncludeWithDeserTest.java b/src/test/java/tools/jackson/databind/deser/IncludeWithDeserTest.java index 0bf6baca5e..fdf3e2dd51 100644 --- a/src/test/java/tools/jackson/databind/deser/IncludeWithDeserTest.java +++ b/src/test/java/tools/jackson/databind/deser/IncludeWithDeserTest.java @@ -125,7 +125,7 @@ public void testSimpleInclude() throws Exception @Test public void testIncludeIgnoredAndUnrecognizedField() throws Exception { - ObjectReader r = MAPPER.readerFor(OnlyY.class); + ObjectReader r = MAPPER.readerFor(OnlyY.class).with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // First, fine to get "y" only: OnlyY result = r.readValue(a2q("{'x':3, 'y': 4}")); diff --git a/src/test/java/tools/jackson/databind/deser/SetterlessPropertiesDeserTest.java b/src/test/java/tools/jackson/databind/deser/SetterlessPropertiesDeserTest.java index 32deaf79b1..656595b473 100644 --- a/src/test/java/tools/jackson/databind/deser/SetterlessPropertiesDeserTest.java +++ b/src/test/java/tools/jackson/databind/deser/SetterlessPropertiesDeserTest.java @@ -74,7 +74,7 @@ public void testSimpleSetterlessCollectionOk() throws Exception @Test public void testSimpleSetterlessCollectionFailure() throws Exception { - ObjectMapper m = new ObjectMapper(); + ObjectMapper m = jsonMapperBuilder().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); assertFalse(m.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS)); // and now this should fail @@ -108,6 +108,7 @@ public void testSimpleSetterlessMapFailure() throws Exception { ObjectMapper m = jsonMapperBuilder() .disable(MapperFeature.USE_GETTERS_AS_SETTERS) + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .build(); // so this should fail now without a setter try { diff --git a/src/test/java/tools/jackson/databind/deser/builder/BuilderFailTest.java b/src/test/java/tools/jackson/databind/deser/builder/BuilderFailTest.java index 55d1dac324..6255a188c6 100644 --- a/src/test/java/tools/jackson/databind/deser/builder/BuilderFailTest.java +++ b/src/test/java/tools/jackson/databind/deser/builder/BuilderFailTest.java @@ -8,9 +8,7 @@ import tools.jackson.databind.exc.UnrecognizedPropertyException; import static org.junit.jupiter.api.Assertions.fail; - -import static tools.jackson.databind.testutil.DatabindTestUtil.a2q; -import static tools.jackson.databind.testutil.DatabindTestUtil.verifyException; +import static tools.jackson.databind.testutil.DatabindTestUtil.*; public class BuilderFailTest { @@ -68,7 +66,8 @@ public ValueClassXY build() { /********************************************************** */ - private final ObjectMapper MAPPER = new ObjectMapper(); + private final ObjectMapper MAPPER = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); @Test public void testBuilderMethodReturnInvalidType() throws Exception diff --git a/src/test/java/tools/jackson/databind/deser/builder/BuilderSimpleTest.java b/src/test/java/tools/jackson/databind/deser/builder/BuilderSimpleTest.java index 4792bca702..73c309dfac 100644 --- a/src/test/java/tools/jackson/databind/deser/builder/BuilderSimpleTest.java +++ b/src/test/java/tools/jackson/databind/deser/builder/BuilderSimpleTest.java @@ -306,7 +306,8 @@ private Value2354 build() { /********************************************************** */ - private final ObjectMapper MAPPER = newJsonMapper(); + private final ObjectMapper MAPPER = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); @Test public void testSimple() throws Exception diff --git a/src/test/java/tools/jackson/databind/deser/creators/AnySetterForCreator562Test.java b/src/test/java/tools/jackson/databind/deser/creators/AnySetterForCreator562Test.java index f03d67f89b..d4b1b20bf2 100644 --- a/src/test/java/tools/jackson/databind/deser/creators/AnySetterForCreator562Test.java +++ b/src/test/java/tools/jackson/databind/deser/creators/AnySetterForCreator562Test.java @@ -217,8 +217,9 @@ public void testAnySetterViaCreator562Disabled() throws Exception { // With 3.0 different fail type, message since we do we get parameter name info try { - MAPPER.readValue(a2q("{'a':'value', 'b':42, 'c': 111}"), - PojoWithDisabled.class); + MAPPER.readerFor(PojoWithDisabled.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(a2q("{'a':'value', 'b':42, 'c': 111}")); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized property \"b\""); diff --git a/src/test/java/tools/jackson/databind/deser/creators/ConstructorDetectorTest.java b/src/test/java/tools/jackson/databind/deser/creators/ConstructorDetectorTest.java index a97ca9f1f6..230b50d00e 100644 --- a/src/test/java/tools/jackson/databind/deser/creators/ConstructorDetectorTest.java +++ b/src/test/java/tools/jackson/databind/deser/creators/ConstructorDetectorTest.java @@ -145,8 +145,9 @@ public void test1ArgDefaultsToPropsMultipleCtors() throws Exception // 23-May-2024, tatu: Will fail differently with [databind#4515]; default // constructor available, implicit ones ignored try { - MAPPER_PROPS.readValue(a2q("{'value' : 137 }"), - SingleArg2CtorsNotAnnotated.class); + MAPPER_PROPS.readerFor(SingleArg2CtorsNotAnnotated.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(a2q("{'value' : 137 }")); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "\"value\""); diff --git a/src/test/java/tools/jackson/databind/deser/creators/CreatorWithRenamedParam4545Test.java b/src/test/java/tools/jackson/databind/deser/creators/CreatorWithRenamedParam4545Test.java index 2950224bdc..40d10b0939 100644 --- a/src/test/java/tools/jackson/databind/deser/creators/CreatorWithRenamedParam4545Test.java +++ b/src/test/java/tools/jackson/databind/deser/creators/CreatorWithRenamedParam4545Test.java @@ -53,7 +53,9 @@ public void testCreatorWithRename4545() throws Exception String jsonPayload = a2q("{ 'key1': 'val1', 'key2': 'val2'}"); try { - MAPPER.readValue(jsonPayload, Payload4545.class); + MAPPER.readerFor(Payload4545.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(jsonPayload); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized"); diff --git a/src/test/java/tools/jackson/databind/deser/filter/IgnorePropertyOnDeserTest.java b/src/test/java/tools/jackson/databind/deser/filter/IgnorePropertyOnDeserTest.java index 0b09f1f153..cf4010ed6f 100644 --- a/src/test/java/tools/jackson/databind/deser/filter/IgnorePropertyOnDeserTest.java +++ b/src/test/java/tools/jackson/databind/deser/filter/IgnorePropertyOnDeserTest.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.UnrecognizedPropertyException; @@ -151,7 +152,9 @@ public void testIgnoreUnknownViaConfigOverride() throws Exception // First, fail without overrides try { - MAPPER.readValue(DOC, Point.class); + MAPPER.readerFor(Point.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(DOC); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "foobar"); // message varies between 2.x and 3.x diff --git a/src/test/java/tools/jackson/databind/deser/filter/UnknownPropertyDeserTest.java b/src/test/java/tools/jackson/databind/deser/filter/UnknownPropertyDeserTest.java index 7759005f79..7d3f5057e2 100644 --- a/src/test/java/tools/jackson/databind/deser/filter/UnknownPropertyDeserTest.java +++ b/src/test/java/tools/jackson/databind/deser/filter/UnknownPropertyDeserTest.java @@ -162,7 +162,9 @@ static class Bean987 { public void testUnknownHandlingDefault() throws Exception { try { - MAPPER.readValue(JSON_UNKNOWN_FIELD, TestBean.class); + MAPPER.readerFor(TestBean.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(JSON_UNKNOWN_FIELD); fail("Should not pass"); } catch (UnrecognizedPropertyException jex) { verifyException(jex, "Unrecognized property \"foo\""); diff --git a/src/test/java/tools/jackson/databind/deser/jdk/VoidProperties2675Test.java b/src/test/java/tools/jackson/databind/deser/jdk/VoidProperties2675Test.java index 825d0d9bda..cd5c3b2714 100644 --- a/src/test/java/tools/jackson/databind/deser/jdk/VoidProperties2675Test.java +++ b/src/test/java/tools/jackson/databind/deser/jdk/VoidProperties2675Test.java @@ -27,10 +27,13 @@ static class VoidBean { /********************************************************************** */ - private final ObjectMapper VOID_MAPPER = sharedMapper(); + private final ObjectMapper VOID_MAPPER = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .build(); private final ObjectMapper NO_VOID_MAPPER = jsonMapperBuilder() .disable(MapperFeature.ALLOW_VOID_VALUED_PROPERTIES) + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .build(); @Test diff --git a/src/test/java/tools/jackson/databind/deser/merge/PropertyMergeTest.java b/src/test/java/tools/jackson/databind/deser/merge/PropertyMergeTest.java index b6fe0e5885..c4228cf2c6 100644 --- a/src/test/java/tools/jackson/databind/deser/merge/PropertyMergeTest.java +++ b/src/test/java/tools/jackson/databind/deser/merge/PropertyMergeTest.java @@ -226,7 +226,8 @@ public void testBeanAsArrayMerging() throws Exception // and finally with extra, failing try { MAPPER.readerForUpdating(input) - .readValue("[9, 8, 14]"); + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue("[9, 8, 14]"); fail("Should not pass"); } catch (MismatchedInputException e) { verifyException(e, "expected at most 2 properties"); diff --git a/src/test/java/tools/jackson/databind/exc/DeserExceptionTypeTest.java b/src/test/java/tools/jackson/databind/exc/DeserExceptionTypeTest.java index 07f815b983..cbcd349b9f 100644 --- a/src/test/java/tools/jackson/databind/exc/DeserExceptionTypeTest.java +++ b/src/test/java/tools/jackson/databind/exc/DeserExceptionTypeTest.java @@ -48,7 +48,9 @@ public void testHandlingOfUnrecognized() throws Exception { UnrecognizedPropertyException exc = null; try { - MAPPER.readValue("{\"bar\":3}", Bean.class); + MAPPER.readerFor(Bean.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue("{\"bar\":3}"); } catch (UnrecognizedPropertyException e) { exc = e; } diff --git a/src/test/java/tools/jackson/databind/introspect/AccessorNamingForBuilderTest.java b/src/test/java/tools/jackson/databind/introspect/AccessorNamingForBuilderTest.java index 466d659a00..189cea5f99 100644 --- a/src/test/java/tools/jackson/databind/introspect/AccessorNamingForBuilderTest.java +++ b/src/test/java/tools/jackson/databind/introspect/AccessorNamingForBuilderTest.java @@ -49,7 +49,8 @@ public ValueClassXY build() { public void testAccessorCustomWithMethod() throws Exception { final String json = a2q("{'x':28,'y':72}"); - final ObjectMapper vanillaMapper = newJsonMapper(); + final ObjectMapper vanillaMapper = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); // First: without custom strategy, will fail: try { diff --git a/src/test/java/tools/jackson/databind/introspect/TestInferredMutators.java b/src/test/java/tools/jackson/databind/introspect/TestInferredMutators.java index 73156955c8..79904b2170 100644 --- a/src/test/java/tools/jackson/databind/introspect/TestInferredMutators.java +++ b/src/test/java/tools/jackson/databind/introspect/TestInferredMutators.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Test; +import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.MapperFeature; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.UnrecognizedPropertyException; @@ -35,6 +36,7 @@ public static class FixedPoint { public void testFinalFieldIgnoral() throws Exception { ObjectMapper mapper = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) .build(); try { @@ -49,7 +51,7 @@ public void testFinalFieldIgnoral() throws Exception public void testDeserializationInference() throws Exception { final String JSON = "{\"x\":2}"; - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = jsonMapperBuilder().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); // First: default case, inference enabled: assertTrue(mapper.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS)); Point p = mapper.readValue(JSON, Point.class); @@ -57,6 +59,7 @@ public void testDeserializationInference() throws Exception // but without it, should fail: mapper = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(MapperFeature.INFER_PROPERTY_MUTATORS) .build(); try { diff --git a/src/test/java/tools/jackson/databind/introspect/TransientTest.java b/src/test/java/tools/jackson/databind/introspect/TransientTest.java index 34e476683a..47afd398f1 100644 --- a/src/test/java/tools/jackson/databind/introspect/TransientTest.java +++ b/src/test/java/tools/jackson/databind/introspect/TransientTest.java @@ -142,8 +142,9 @@ public void testOverridingTransient() throws Exception public void testTransientToPrune() throws Exception { try { - TransientToPrune result = MAPPER.readValue("{\"a\":3}", - TransientToPrune.class); + TransientToPrune result = MAPPER.readerFor(TransientToPrune.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue("{\"a\":3}"); fail("Should not pass, got: "+result); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized", "\"a\""); diff --git a/src/test/java/tools/jackson/databind/jsontype/TestMultipleTypeNames.java b/src/test/java/tools/jackson/databind/jsontype/TestMultipleTypeNames.java index f28bd7af67..3bffd5ac0a 100644 --- a/src/test/java/tools/jackson/databind/jsontype/TestMultipleTypeNames.java +++ b/src/test/java/tools/jackson/databind/jsontype/TestMultipleTypeNames.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.exc.InvalidDefinitionException; import tools.jackson.databind.exc.UnrecognizedPropertyException; @@ -17,7 +18,8 @@ // Tests for [databind#2761] (and [annotations#171] public class TestMultipleTypeNames extends DatabindTestUtil { - private final ObjectMapper MAPPER = newJsonMapper(); + private final ObjectMapper MAPPER = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); // common classes static class MultiTypeName { } @@ -156,7 +158,9 @@ public void testNameAndNames() throws Exception // TC 2 : incorrect serialisation json = "{\"data\": [{\"type\":\"a\", \"data\": {\"x\": 2.2}}, {\"type\":\"b\", \"data\": {\"y\": 5.3}}, {\"type\":\"c\", \"data\": {\"y\": 9.8}}]}"; try { - MAPPER.readValue(json, WrapperForNameAndNamesTest.class); + MAPPER.readerFor(WrapperForNameAndNamesTest.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(json); fail("This serialisation should fail 'coz of x being float"); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized property \"data\""); diff --git a/src/test/java/tools/jackson/databind/misc/CaseInsensitiveDeserTest.java b/src/test/java/tools/jackson/databind/misc/CaseInsensitiveDeserTest.java index c888ca9e59..52ec3084b7 100644 --- a/src/test/java/tools/jackson/databind/misc/CaseInsensitiveDeserTest.java +++ b/src/test/java/tools/jackson/databind/misc/CaseInsensitiveDeserTest.java @@ -133,7 +133,8 @@ public void testCaseInsensitiveDeserialization() throws Exception final String JSON = "{\"Value1\" : {\"nAme\" : \"fruit\", \"vALUe\" : \"apple\"}, \"valUE2\" : {\"NAME\" : \"color\", \"value\" : \"red\"}}"; // first, verify default settings which do not accept improper case - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); assertFalse(mapper.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)); try { mapper.readValue(JSON, Issue476Bean.class); @@ -233,8 +234,9 @@ public void testCaseInsensitiveViaClassAnnotation() throws Exception // and finally, more complicated; should be possible to force sensitivity: try { - /*CaseSensitiveRoleContainer r =*/ MAPPER.readValue(CONTAINED, - CaseSensitiveRoleContainer.class); + /*CaseSensitiveRoleContainer r =*/ jsonMapperBuilder() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build() + .readValue(CONTAINED, CaseSensitiveRoleContainer.class); fail("Should not pass"); } catch (UnrecognizedPropertyException e) { verifyException(e, "Unrecognized "); diff --git a/src/test/java/tools/jackson/databind/module/SimpleModuleTest.java b/src/test/java/tools/jackson/databind/module/SimpleModuleTest.java index ec137693dd..d6d983bc5b 100644 --- a/src/test/java/tools/jackson/databind/module/SimpleModuleTest.java +++ b/src/test/java/tools/jackson/databind/module/SimpleModuleTest.java @@ -211,7 +211,7 @@ public void serialize(Test3787Bean value, JsonGenerator gen, SerializerProvider @Test public void testWithoutModule() { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = jsonMapperBuilder().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(); // first: serialization failure: try { mapper.writeValueAsString(new CustomBean("foo", 3)); diff --git a/src/test/java/tools/jackson/databind/seq/ReadRecoveryTest.java b/src/test/java/tools/jackson/databind/seq/ReadRecoveryTest.java index bb763fb1cb..1aa891140f 100644 --- a/src/test/java/tools/jackson/databind/seq/ReadRecoveryTest.java +++ b/src/test/java/tools/jackson/databind/seq/ReadRecoveryTest.java @@ -32,7 +32,9 @@ static class Bean { public void testRootBeans() throws Exception { final String JSON = a2q("{'a':3} {'x':5}"); - MappingIterator it = MAPPER.readerFor(Bean.class).readValues(JSON); + MappingIterator it = MAPPER.readerFor(Bean.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValues(JSON); // First one should be fine assertTrue(it.hasNextValue()); Bean bean = it.nextValue(); @@ -58,7 +60,9 @@ public void testSimpleRootRecovery() throws Exception { final String JSON = a2q("{'a':3}{'a':27,'foo':[1,2],'b':{'x':3}} {'a':1,'b':2} "); - MappingIterator it = MAPPER.readerFor(Bean.class).readValues(JSON); + MappingIterator it = MAPPER.readerFor(Bean.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValues(JSON); Bean bean = it.nextValue(); assertNotNull(bean); @@ -88,7 +92,9 @@ public void testSimpleArrayRecovery() throws Exception { final String JSON = a2q("[{'a':3},{'a':27,'foo':[1,2],'b':{'x':3}} ,{'a':1,'b':2} ]"); - MappingIterator it = MAPPER.readerFor(Bean.class).readValues(JSON); + MappingIterator it = MAPPER.readerFor(Bean.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValues(JSON); Bean bean = it.nextValue(); assertNotNull(bean); diff --git a/src/test/java/tools/jackson/databind/struct/TestPOJOAsArray.java b/src/test/java/tools/jackson/databind/struct/TestPOJOAsArray.java index be5b26d6c9..6caf5b5ab6 100644 --- a/src/test/java/tools/jackson/databind/struct/TestPOJOAsArray.java +++ b/src/test/java/tools/jackson/databind/struct/TestPOJOAsArray.java @@ -295,7 +295,9 @@ public void testUnknownExtraProp() throws Exception { String json = "{\"value\":[true,\"Foobar\",42,13, false]}"; try { - MAPPER.readValue(json, PojoAsArrayWrapper.class); + MAPPER.readerFor(PojoAsArrayWrapper.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(json); fail("should not pass with extra element"); } catch (MismatchedInputException e) { verifyException(e, "Unexpected JSON values"); diff --git a/src/test/java/tools/jackson/databind/struct/TestPOJOAsArrayWithBuilder.java b/src/test/java/tools/jackson/databind/struct/TestPOJOAsArrayWithBuilder.java index 5ed98e3ea0..6dcfb09a06 100644 --- a/src/test/java/tools/jackson/databind/struct/TestPOJOAsArrayWithBuilder.java +++ b/src/test/java/tools/jackson/databind/struct/TestPOJOAsArrayWithBuilder.java @@ -195,7 +195,9 @@ public void testUnknownExtraProp() throws Exception { String json = "[1, 2, 3, 4]"; try { - MAPPER.readValue(json, ValueClassXY.class); + MAPPER.readerFor(ValueClassXY.class) + .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .readValue(json); fail("should not pass with extra element"); } catch (MismatchedInputException e) { verifyException(e, "Unexpected JSON values");