Skip to content

Commit

Permalink
Fix #664
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 2, 2015
1 parent 07d0e79 commit 8e9d4b2
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 232 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION
Expand Up @@ -10,6 +10,9 @@ Project: jackson-databind
#348: ObjectMapper.valueToTree does not work with @JsonRawValue #348: ObjectMapper.valueToTree does not work with @JsonRawValue
(reported by Chris P, pimlottc@github) (reported by Chris P, pimlottc@github)
#649: Make `BeanDeserializer` use new `parser.nextFieldName()` and `.hasTokenId()` methods #649: Make `BeanDeserializer` use new `parser.nextFieldName()` and `.hasTokenId()` methods
#664: Add `DeserializationFeature.ACCEPT_FLOAT_AS_INT` to prevent coercion of floating point
numbers int `int`/`long`/`Integer`/`Long`
(requested by wenzis@github)
#679: Add `isEmpty()` implementation for `JsonNode` serializers #679: Add `isEmpty()` implementation for `JsonNode` serializers
#688: Provide a means for an ObjectMapper to discover mixin annotation classes on demand #688: Provide a means for an ObjectMapper to discover mixin annotation classes on demand
(requested by Laird N) (requested by Laird N)
Expand Down
Expand Up @@ -685,7 +685,8 @@ public Date parseDate(String dateStr) throws IllegalArgumentException
DateFormat df = getDateFormat(); DateFormat df = getDateFormat();
return df.parse(dateStr); return df.parse(dateStr);
} catch (ParseException e) { } catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse Date value '"+dateStr+"': "+e.getMessage()); throw new IllegalArgumentException(String.format(
"Failed to parse Date value '%s': %s", dateStr, e.getMessage()));
} }
} }


Expand Down Expand Up @@ -826,7 +827,9 @@ public JsonMappingException mappingException(Class<?> targetClass) {
} }


public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) { public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) {
return JsonMappingException.from(_parser, "Can not deserialize instance of "+_calcName(targetClass)+" out of "+token+" token"); return JsonMappingException.from(_parser,
String.format("Can not deserialize instance of %s out of %s token",
_calcName(targetClass), token));
} }


/** /**
Expand All @@ -844,23 +847,12 @@ public JsonMappingException mappingException(String message) {
*/ */
public JsonMappingException instantiationException(Class<?> instClass, Throwable t) { public JsonMappingException instantiationException(Class<?> instClass, Throwable t) {
return JsonMappingException.from(_parser, return JsonMappingException.from(_parser,
"Can not construct instance of "+instClass.getName()+", problem: "+t.getMessage(), t); String.format("Can not construct instance of %s, problem: %s", instClass.getName(), t.getMessage()), t);
} }


public JsonMappingException instantiationException(Class<?> instClass, String msg) { public JsonMappingException instantiationException(Class<?> instClass, String msg) {
return JsonMappingException.from(_parser, "Can not construct instance of "+instClass.getName()+", problem: "+msg); return JsonMappingException.from(_parser,
} String.format("Can not construct instance of %s, problem: %s", instClass.getName(), msg));

/**
* Method that will construct an exception suitable for throwing when
* some String values are acceptable, but the one encountered is not.
*
*
* @deprecated Since 2.1 should use variant that takes value
*/
@Deprecated
public JsonMappingException weirdStringException(Class<?> instClass, String msg) {
return weirdStringException(null, instClass, msg);
} }


/** /**
Expand All @@ -875,26 +867,19 @@ public JsonMappingException weirdStringException(Class<?> instClass, String msg)
*/ */
public JsonMappingException weirdStringException(String value, Class<?> instClass, String msg) { public JsonMappingException weirdStringException(String value, Class<?> instClass, String msg) {
return InvalidFormatException.from(_parser, return InvalidFormatException.from(_parser,
"Can not construct instance of "+instClass.getName()+" from String value '"+_valueDesc()+"': "+msg, String.format("Can not construct instance of %s from String value '%s': %s",
instClass.getName(), _valueDesc(), msg),
value, instClass); value, instClass);
} }


/**
* Helper method for constructing exception to indicate that input JSON
* Number was not suitable for deserializing into given type.
*/
@Deprecated
public JsonMappingException weirdNumberException(Class<?> instClass, String msg) {
return weirdStringException(null, instClass, msg);
}

/** /**
* Helper method for constructing exception to indicate that input JSON * Helper method for constructing exception to indicate that input JSON
* Number was not suitable for deserializing into given target type. * Number was not suitable for deserializing into given target type.
*/ */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) { public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) {
return InvalidFormatException.from(_parser, return InvalidFormatException.from(_parser,
"Can not construct instance of "+instClass.getName()+" from number value ("+_valueDesc()+"): "+msg, String.format("Can not construct instance of %s from number value (%s): %s",
instClass.getName(), _valueDesc(), msg),
null, instClass); null, instClass);
} }


Expand All @@ -905,7 +890,8 @@ public JsonMappingException weirdNumberException(Number value, Class<?> instClas
*/ */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg) { public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg) {
return InvalidFormatException.from(_parser, return InvalidFormatException.from(_parser,
"Can not construct Map key of type "+keyClass.getName()+" from String \""+_desc(keyValue)+"\": "+msg, String.format("Can not construct Map key of type %s from String \"%s\": ",
keyClass.getName(), _desc(keyValue), msg),
keyValue, keyClass); keyValue, keyClass);
} }


Expand All @@ -914,7 +900,8 @@ public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue
* token. * token.
*/ */
public JsonMappingException wrongTokenException(JsonParser p, JsonToken expToken, String msg0) { public JsonMappingException wrongTokenException(JsonParser p, JsonToken expToken, String msg0) {
String msg = "Unexpected token ("+p.getCurrentToken()+"), expected "+expToken; String msg = String.format("Unexpected token (%s), expected %s",
p.getCurrentToken(), expToken);
if (msg0 != null) { if (msg0 != null) {
msg = msg + ": "+msg0; msg = msg + ": "+msg0;
} }
Expand Down
Expand Up @@ -280,6 +280,20 @@ public enum DeserializationFeature implements ConfigFeature
* @since 2.5 * @since 2.5
*/ */
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT(false), ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT(false),

/**
* Feature that determines whether coercion from JSON floating point
* number (anything with command (`.`) or exponent portion (`e` / `E'))
* to an expected integral number (`int`, `long`, `java.lang.Integer`, `java.lang.Long`,
* `java.math.BigDecimal`) is allowed or not.
* If enabled, coercion truncates value; if disabled, a {@link JsonMappingException}
* will be thrown.
*<p>
* Feature is enabled by default.
*
* @since 2.6
*/
ACCEPT_FLOAT_AS_INT(true),


/** /**
* Feature that allows unknown Enum values to be parsed as null values. * Feature that allows unknown Enum values to be parsed as null values.
Expand Down

0 comments on commit 8e9d4b2

Please sign in to comment.