aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java')
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java
new file mode 100644
index 000000000..7e1f6ea51
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java
@@ -0,0 +1,52 @@
+package com.fasterxml.jackson.databind.deser;
+
+import com.fasterxml.jackson.annotation.*;
+
+import com.fasterxml.jackson.databind.*;
+
+public class ReadOnlyDeserFailOnUnknown2719Test extends BaseMapTest
+{
+ // [databind#2719]
+ static class UserWithReadOnly {
+ @JsonProperty(value = "username", access = JsonProperty.Access.READ_ONLY)
+ public String name;
+ @JsonProperty(access = JsonProperty.Access.READ_ONLY)
+ public String password;
+ public String login;
+ }
+
+ /*
+ /**********************************************************
+ /* Test methods
+ /**********************************************************
+ */
+
+ private final ObjectMapper MAPPER = newJsonMapper();
+
+ public void testFailOnIgnore() throws Exception
+ {
+ ObjectReader r = MAPPER.readerFor(UserWithReadOnly.class);
+
+ // First, fine to get 'login'
+ UserWithReadOnly result = r.readValue(aposToQuotes("{'login':'foo'}"));
+ assertEquals("foo", result.login);
+
+ // but not 'password'
+ r = r.with(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
+ try {
+ r.readValue(aposToQuotes("{'login':'foo', 'password':'bar'}"));
+ fail("Should fail");
+ } catch (JsonMappingException e) {
+ verifyException(e, "Ignored field");
+ }
+
+ // or 'username'
+ r = r.with(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
+ try {
+ r.readValue(aposToQuotes("{'login':'foo', 'username':'bar'}"));
+ fail("Should fail");
+ } catch (JsonMappingException e) {
+ verifyException(e, "Ignored field");
+ }
+ }
+}