Skip to content

Commit

Permalink
Merge pull request FasterXML#387 from yinzara/master
Browse files Browse the repository at this point in the history
Requested changes for new UNWRAP_SINGLE_VALUE_ARRAYS DeserializationFeature
  • Loading branch information
cowtowncoder committed Jan 12, 2014
2 parents 80e1b7e + 00cb595 commit 52313b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public enum DeserializationFeature implements ConfigFeature
* values to the corresponding value type. This is basically the opposite of the {@link #ACCEPT_SINGLE_VALUE_AS_ARRAY}
* feature. If more than one value is found in the array, a JsonMappingException is thrown.
* <p>
* Feature is disabled by default.
*
* Feature is disabled by default
* @since 2.4
*/
UNWRAP_SINGLE_VALUE_ARRAYS(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ public Character deserialize(JsonParser jp, DeserializationContext ctxt)
);
}
return value;
} else if (t == JsonToken.VALUE_NULL && !_valueClass.isPrimitive()) {
//Issue#unreported
// This handles the case where the value required is the Character wrapper class and the token is the null token
return getEmptyValue();
}
throw ctxt.mappingException(_valueClass, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ final static class FloatBean {
float _v;
void setV(float v) { _v = v; }
}

final static class CharacterBean {
char _v;
void setV(char v) { _v = v; }
char getV() { return _v; }
}

final static class CharacterWrapperBean {
Character _v;
void setV(Character v) { _v = v; }
Character getV() { return _v; }
}

/**
* Also, let's ensure that it's ok to override methods.
Expand Down Expand Up @@ -305,6 +317,24 @@ public void testCharacterWrapper() throws Exception
// But can also pass in ascii code
result = MAPPER.readValue(new StringReader(" "+((int) 'X')), Character.class);
assertEquals(Character.valueOf('X'), result);

final CharacterWrapperBean wrapper = MAPPER.readValue(new StringReader("{\"v\":null}"), CharacterWrapperBean.class);
assertNotNull(wrapper);
assertNull(wrapper.getV());

final ObjectMapper mapper = new ObjectMapper();
try {
mapper.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
mapper.readValue("{\"v\":null}", CharacterBean.class);
fail("Attempting to deserialize a 'null' JSON reference into a 'char' property did not throw an exception");
} catch (JsonMappingException exp) {
//Exception thrown as required
}

mapper.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
final CharacterBean charBean = MAPPER.readValue(new StringReader("{\"v\":null}"), CharacterBean.class);
assertNotNull(wrapper);
assertEquals('\u0000', charBean.getV());
}

public void testIntWrapper() throws Exception
Expand Down

0 comments on commit 52313b8

Please sign in to comment.