Minor tweaks to #1533
diff --git a/release-notes/VERSION b/release-notes/VERSION
index f902da9..53f0036 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -3,6 +3,10 @@
=== Releases ===
------------------------------------------------------------------------
+2.8.8 (not yet released)
+
+#1533: `AsPropertyTypeDeserializer` ignores `DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT`
+
2.8.7 (21-Feb-2017)
#935: `@JsonProperty(access = Access.READ_ONLY)` - unexpected behaviour
diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java
index 7941e05..daf3271 100644
--- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java
@@ -151,9 +151,10 @@
return result;
}
// or, something for which "as-property" won't work, changed into "wrapper-array" type:
- if (p.getCurrentToken() == JsonToken.START_ARRAY) {
+ if (p.isExpectedStartArrayToken()) {
return super.deserializeTypedFromAny(p, ctxt);
- } else if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
+ }
+ if (p.hasToken(JsonToken.VALUE_STRING)) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = p.getText().trim();
if (str.isEmpty()) {
diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java
index 0e293c5..439b7d6 100644
--- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java
+++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java
@@ -129,10 +129,10 @@
public BaseClass value;
}
+ // [databind#1533]
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY,
property = "type")
static class AsProperty {
-
}
static class AsPropertyWrapper {
@@ -259,19 +259,23 @@
public void testWithoutEmptyStringAsNullObject1533() throws Exception
{
- ObjectMapper mapper = new ObjectMapper().disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
+ ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
+ .without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
try {
- mapper.readValue("{ \"value\": \"\" }", AsPropertyWrapper.class);
+ r.readValue("{ \"value\": \"\" }");
fail("Expected " + JsonMappingException.class);
} catch (JsonMappingException e) {
- // expected
+ verifyException(e, "missing property 'type'");
+ verifyException(e, "contain type id");
}
}
+ // [databind#1533]
public void testWithEmptyStringAsNullObject1533() throws Exception
{
- ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
- AsPropertyWrapper wrapper = mapper.readValue("{ \"value\": \"\" }", AsPropertyWrapper.class);
+ ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
+ .with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
+ AsPropertyWrapper wrapper = r.readValue("{ \"value\": \"\" }");
assertNull(wrapper.value);
}