Skip to content

Commit 5bd7605

Browse files
committed
Minor tweaks to #1533
1 parent 10d5ab3 commit 5bd7605

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

release-notes/VERSION

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Project: jackson-databind
33
=== Releases ===
44
------------------------------------------------------------------------
55

6+
2.8.8 (not yet released)
7+
8+
#1533: `AsPropertyTypeDeserializer` ignores `DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT`
9+
610
2.8.7 (21-Feb-2017)
711

812
#935: `@JsonProperty(access = Access.READ_ONLY)` - unexpected behaviour

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ protected Object _deserializeTypedUsingDefaultImpl(JsonParser p, Deserialization
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);
156-
} else if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
156+
}
157+
if (p.hasToken(JsonToken.VALUE_STRING)) {
157158
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
158159
String str = p.getText().trim();
159160
if (str.isEmpty()) {

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

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

132+
// [databind#1533]
132133
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY,
133134
property = "type")
134135
static class AsProperty {
135-
136136
}
137137

138138
static class AsPropertyWrapper {
@@ -259,19 +259,23 @@ public void testUnknownClassAsSubtype() throws Exception
259259

260260
public void testWithoutEmptyStringAsNullObject1533() throws Exception
261261
{
262-
ObjectMapper mapper = new ObjectMapper().disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
262+
ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
263+
.without(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
263264
try {
264-
mapper.readValue("{ \"value\": \"\" }", AsPropertyWrapper.class);
265+
r.readValue("{ \"value\": \"\" }");
265266
fail("Expected " + JsonMappingException.class);
266267
} catch (JsonMappingException e) {
267-
// expected
268+
verifyException(e, "missing property 'type'");
269+
verifyException(e, "contain type id");
268270
}
269271
}
270272

273+
// [databind#1533]
271274
public void testWithEmptyStringAsNullObject1533() throws Exception
272275
{
273-
ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
274-
AsPropertyWrapper wrapper = mapper.readValue("{ \"value\": \"\" }", AsPropertyWrapper.class);
276+
ObjectReader r = MAPPER.readerFor(AsPropertyWrapper.class)
277+
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
278+
AsPropertyWrapper wrapper = r.readValue("{ \"value\": \"\" }");
275279
assertNull(wrapper.value);
276280
}
277281

0 commit comments

Comments
 (0)