Skip to content

Commit cb38b3d

Browse files
committed
Merge branch '2.8'
2 parents 54fb5a3 + 5bd7605 commit cb38b3d

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

release-notes/VERSION

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ Project: jackson-databind
5353
#1454: Support `@JsonFormat.lenient` for `java.util.Date`, `java.util.Calendar`
5454
#1474: Replace use of `Class.newInstance()` (deprecated in Java 9) with call via Constructor
5555

56-
2.8.7 (not yet released)
56+
2.8.8 (not yet released)
57+
58+
#1533: `AsPropertyTypeDeserializer` ignores `DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT`
59+
60+
2.8.7 (21-Feb-2017)
5761

5862
#935: `@JsonProperty(access = Access.READ_ONLY)` - unexpected behaviour
5963
#1317: '@JsonIgnore' annotation not working with creator properties, serialization

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,20 @@ protected Object _deserializeTypedUsingDefaultImpl(JsonParser p,
151151
return result;
152152
}
153153
// or, something for which "as-property" won't work, changed into "wrapper-array" type:
154-
if (p.getCurrentToken() == JsonToken.START_ARRAY) {
154+
if (p.isExpectedStartArrayToken()) {
155155
return super.deserializeTypedFromAny(p, ctxt);
156156
}
157+
if (p.hasToken(JsonToken.VALUE_STRING)) {
158+
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
159+
String str = p.getText().trim();
160+
if (str.isEmpty()) {
161+
return null;
162+
}
163+
}
164+
}
157165
ctxt.reportWrongTokenException(baseType(), JsonToken.FIELD_NAME,
158-
"missing property '"+_typePropertyName+"' that is to contain type id (for class "+baseTypeName()+")");
166+
String.format("missing property '%s' that is to contain type id (for class %s)",
167+
_typePropertyName, baseTypeName()));
159168
return null;
160169
}
161170

src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl.java

+32
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ static class BaseWrapper {
129129
public BaseClass value;
130130
}
131131

132+
// [databind#1533]
133+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY,
134+
property = "type")
135+
static class AsProperty {
136+
}
137+
138+
static class AsPropertyWrapper {
139+
public AsProperty value;
140+
}
141+
132142
/*
133143
/**********************************************************
134144
/* Unit tests, deserialization
@@ -247,6 +257,28 @@ public void testUnknownClassAsSubtype() throws Exception
247257
assertNull(w.value);
248258
}
249259

260+
public void testWithoutEmptyStringAsNullObject1533() throws Exception
261+
{
262+
ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
263+
.without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
264+
try {
265+
r.readValue("{ \"value\": \"\" }");
266+
fail("Expected " + JsonMappingException.class);
267+
} catch (JsonMappingException e) {
268+
verifyException(e, "missing property 'type'");
269+
verifyException(e, "contain type id");
270+
}
271+
}
272+
273+
// [databind#1533]
274+
public void testWithEmptyStringAsNullObject1533() throws Exception
275+
{
276+
ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
277+
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
278+
AsPropertyWrapper wrapper = r.readValue("{ \"value\": \"\" }");
279+
assertNull(wrapper.value);
280+
}
281+
250282
/*
251283
/**********************************************************
252284
/* Unit tests, serialization

0 commit comments

Comments
 (0)