Skip to content

Commit

Permalink
Merge branch '2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 13, 2020
2 parents 4bbd207 + 26414f5 commit c1f9377
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ protected final byte _parseBytePrimitive(DeserializationContext ctxt, JsonParser
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
return (Byte) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid Byte value");
"not a valid `byte` value");
}
// So far so good: but does it fit?
// as per [JACKSON-804], allow range up to 255, inclusive
Expand Down Expand Up @@ -500,7 +500,7 @@ protected final short _parseShortPrimitive(DeserializationContext ctxt, JsonPars
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
return (Short) ctxt.handleWeirdStringValue(Short.TYPE, text,
"not a valid Short value");
"not a valid `short` value");
}
if (_shortOverflow(value)) {
return (Short) ctxt.handleWeirdStringValue(Short.TYPE, text,
Expand Down Expand Up @@ -588,7 +588,7 @@ protected final int _parseIntPrimitive(DeserializationContext ctxt, String text)
if (text.length() > 9) {
long l = Long.parseLong(text);
if (_intOverflow(l)) {
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
Number v = (Number) ctxt.handleWeirdStringValue(Integer.TYPE, text,
"Overflow: numeric value (%s) out of range of int (%d -%d)",
text, Integer.MIN_VALUE, Integer.MAX_VALUE);
return _nonNullNumber(v).intValue();
Expand All @@ -597,8 +597,8 @@ protected final int _parseIntPrimitive(DeserializationContext ctxt, String text)
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid int value");
Number v = (Number) ctxt.handleWeirdStringValue(Integer.TYPE, text,
"not a valid `int` value");
return _nonNullNumber(v).intValue();
}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ protected final long _parseLongPrimitive(DeserializationContext ctxt, JsonParser
}
return _parseLongPrimitive(ctxt, text);
case JsonTokenId.ID_NUMBER_FLOAT:
act = _checkFloatToIntCoercion(ctxt, p, Integer.TYPE);
act = _checkFloatToIntCoercion(ctxt, p, Long.TYPE);
if (act == CoercionAction.AsNull) {
return 0L;
}
Expand All @@ -654,7 +654,7 @@ protected final long _parseLongPrimitive(DeserializationContext ctxt, JsonParser
break;
default:
}
return ((Number) ctxt.handleUnexpectedToken(getValueType(ctxt), p)).longValue();
return ((Number) ctxt.handleUnexpectedToken(ctxt.constructType(Long.TYPE), p)).longValue();
}

protected final long _parseLongPrimitive(DeserializationContext ctxt, String text) throws IOException
Expand All @@ -663,8 +663,8 @@ protected final long _parseLongPrimitive(DeserializationContext ctxt, String tex
return NumberInput.parseLong(text);
} catch (IllegalArgumentException iae) { }
{
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid long value");
Number v = (Number) ctxt.handleWeirdStringValue(Long.TYPE, text,
"not a valid `long` value");
return _nonNullNumber(v).longValue();
}
}
Expand Down Expand Up @@ -711,8 +711,7 @@ protected final float _parseFloatPrimitive(DeserializationContext ctxt, JsonPars
}
break;
}
// Otherwise, no can do:
return ((Number) ctxt.handleUnexpectedToken(getValueType(ctxt), p)).floatValue();
return ((Number) ctxt.handleUnexpectedToken(ctxt.constructType(Float.TYPE), p)).floatValue();
}

/**
Expand All @@ -739,8 +738,8 @@ protected final float _parseFloatPrimitive(DeserializationContext ctxt, String t
try {
return Float.parseFloat(text);
} catch (IllegalArgumentException iae) { }
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid float value");
Number v = (Number) ctxt.handleWeirdStringValue(Float.TYPE, text,
"not a valid `float` value");
return _nonNullNumber(v).floatValue();
}

Expand Down Expand Up @@ -786,13 +785,9 @@ protected final double _parseDoublePrimitive(DeserializationContext ctxt, JsonPa
}
break;
}
// Otherwise, no can do:
return ((Number) ctxt.handleUnexpectedToken(getValueType(ctxt), p)).doubleValue();
return ((Number) ctxt.handleUnexpectedToken(ctxt.constructType(Double.TYPE), p)).doubleValue();
}

/**
* @since 2.9
*/
protected final double _parseDoublePrimitive(DeserializationContext ctxt, String text)
throws IOException
{
Expand All @@ -816,8 +811,8 @@ protected final double _parseDoublePrimitive(DeserializationContext ctxt, String
try {
return parseDouble(text);
} catch (IllegalArgumentException iae) { }
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid double value (as String to convert)");
Number v = (Number) ctxt.handleWeirdStringValue(Double.TYPE, text,
"not a valid `double` value (as String to convert)");
return _nonNullNumber(v).doubleValue();
}

Expand All @@ -836,7 +831,7 @@ protected java.util.Date _parseDate(JsonParser p, DeserializationContext ctxt)
// (but leave both until 3.0)
} catch (JsonParseException | InputCoercionException e) {
Number v = (Number) ctxt.handleWeirdNumberValue(_valueClass, p.getNumberValue(),
"not a valid 64-bit long for creating `java.util.Date`");
"not a valid 64-bit `long` for creating `java.util.Date`");
ts = v.longValue();
}
return new java.util.Date(ts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,10 @@ public void testInvalidStringCoercionFail() throws IOException
// char[] is special, cannot use generalized test here
// _testInvalidStringCoercionFail(char[].class);
_testInvalidStringCoercionFail(short[].class, "short");
_testInvalidStringCoercionFail(int[].class);
_testInvalidStringCoercionFail(long[].class);
_testInvalidStringCoercionFail(float[].class);
_testInvalidStringCoercionFail(double[].class);
_testInvalidStringCoercionFail(int[].class, "int");
_testInvalidStringCoercionFail(long[].class, "long");
_testInvalidStringCoercionFail(float[].class, "float");
_testInvalidStringCoercionFail(double[].class, "double");
}

private void _testInvalidStringCoercionFail(Class<?> cls) throws IOException
Expand Down

0 comments on commit c1f9377

Please sign in to comment.