Skip to content

Commit d127602

Browse files
committed
Minor cleanup for default/standard parsing of number types, unify internal api of StdDeserializer
1 parent b7c022d commit d127602

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

src/main/java/tools/jackson/databind/deser/jdk/NumberDeserializers.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,8 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt)
628628
if (_checkTextualNull(ctxt, text)) {
629629
return (Float) getNullValue(ctxt);
630630
}
631-
try {
632-
return NumberInput.parseFloat(text, p.isEnabled(StreamReadFeature.USE_FAST_DOUBLE_PARSER));
633-
} catch (IllegalArgumentException iae) { }
634-
return (Float) ctxt.handleWeirdStringValue(_valueClass, text,
635-
"not a valid `Float` value");
631+
// No separate "_parseFloat()" so just call this (nulls handled above)
632+
return _parseFloatPrimitive(p, ctxt, text);
636633
}
637634
}
638635

@@ -725,11 +722,8 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t
725722
if (_checkTextualNull(ctxt, text)) {
726723
return (Double) getNullValue(ctxt);
727724
}
728-
try {
729-
return _parseDouble(text, p.isEnabled(StreamReadFeature.USE_FAST_DOUBLE_PARSER));
730-
} catch (IllegalArgumentException iae) { }
731-
return (Double) ctxt.handleWeirdStringValue(_valueClass, text,
732-
"not a valid `Double` value");
725+
// No separate "_parseDouble()" so just call this (as nulls are handled)
726+
return _parseDoublePrimitive(p, ctxt, text);
733727
}
734728
}
735729

src/main/java/tools/jackson/databind/deser/std/StdDeserializer.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ protected T _deserializeFromString(JsonParser p, DeserializationContext ctxt)
236236
if (inst.canCreateFromInt()) {
237237
if (ctxt.findCoercionAction(LogicalType.Integer, Integer.class,
238238
CoercionInputShape.String) == CoercionAction.TryConvert) {
239-
return (T) inst.createFromInt(ctxt, _parseIntPrimitive(ctxt, value));
239+
return (T) inst.createFromInt(ctxt, _parseIntPrimitive(p, ctxt, value));
240240
}
241241
}
242242
if (inst.canCreateFromLong()) {
243243
if (ctxt.findCoercionAction(LogicalType.Integer, Long.class,
244244
CoercionInputShape.String) == CoercionAction.TryConvert) {
245-
return (T) inst.createFromLong(ctxt, _parseLongPrimitive(ctxt, value));
245+
return (T) inst.createFromLong(ctxt, _parseLongPrimitive(p, ctxt, value));
246246
}
247247
}
248248
if (inst.canCreateFromBoolean()) {
@@ -687,10 +687,11 @@ protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt
687687
_verifyNullForPrimitiveCoercion(ctxt, text);
688688
return 0;
689689
}
690-
return _parseIntPrimitive(ctxt, text);
690+
return _parseIntPrimitive(p, ctxt, text);
691691
}
692692

693-
protected final int _parseIntPrimitive(DeserializationContext ctxt, String text) throws JacksonException
693+
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt,
694+
String text) throws JacksonException
694695
{
695696
try {
696697
if (text.length() > 9) {
@@ -757,10 +758,11 @@ protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt,
757758
if (_checkTextualNull(ctxt, text)) {
758759
return (Integer) getNullValue(ctxt);
759760
}
760-
return _parseInteger(ctxt, text);
761+
return _parseInteger(p, ctxt, text);
761762
}
762763

763-
protected final Integer _parseInteger(DeserializationContext ctxt, String text)
764+
protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt,
765+
String text)
764766
{
765767
try {
766768
if (text.length() > 9) {
@@ -832,10 +834,11 @@ protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ct
832834
_verifyNullForPrimitiveCoercion(ctxt, text);
833835
return 0L;
834836
}
835-
return _parseLongPrimitive(ctxt, text);
837+
return _parseLongPrimitive(p, ctxt, text);
836838
}
837839

838-
protected final long _parseLongPrimitive(DeserializationContext ctxt, String text) throws JacksonException
840+
protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt,
841+
String text) throws JacksonException
839842
{
840843
try {
841844
return NumberInput.parseLong(text);
@@ -1093,18 +1096,6 @@ protected final double _parseDoublePrimitive(JsonParser p, DeserializationContex
10931096
return _nonNullNumber(v).doubleValue();
10941097
}
10951098

1096-
/**
1097-
* Helper method for encapsulating calls to low-level double value parsing; single place
1098-
* just because we need a work-around that must be applied to all calls.
1099-
* Does not use the new <code>useFastParser</code> support.
1100-
*
1101-
* @see #_parseDouble(String, boolean)
1102-
*/
1103-
protected final static double _parseDouble(final String numStr) throws NumberFormatException
1104-
{
1105-
return _parseDouble(numStr, false);
1106-
}
1107-
11081099
/**
11091100
* Helper method for encapsulating calls to low-level double value parsing; single place
11101101
* just because we need a work-around that must be applied to all calls.

src/main/java/tools/jackson/databind/ext/jdk8/OptionalIntDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public OptionalInt deserialize(JsonParser p, DeserializationContext ctxt)
4545
if (_checkTextualNull(ctxt, text)) {
4646
return (OptionalInt) getNullValue(ctxt);
4747
}
48-
return OptionalInt.of(_parseIntPrimitive(ctxt, text));
48+
return OptionalInt.of(_parseIntPrimitive(p, ctxt, text));
4949
case JsonTokenId.ID_NUMBER_FLOAT:
5050
act = _checkFloatToIntCoercion(p, ctxt, _valueClass);
5151
if (act == CoercionAction.AsNull) {

src/main/java/tools/jackson/databind/ext/jdk8/OptionalLongDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public OptionalLong deserialize(JsonParser p, DeserializationContext ctxt)
4545
if (_checkTextualNull(ctxt, text)) {
4646
return (OptionalLong) getNullValue(ctxt);
4747
}
48-
return OptionalLong.of(_parseLongPrimitive(ctxt, text));
48+
return OptionalLong.of(_parseLongPrimitive(p, ctxt, text));
4949
case JsonTokenId.ID_NUMBER_FLOAT:
5050
act = _checkFloatToIntCoercion(p, ctxt, _valueClass);
5151
if (act == CoercionAction.AsNull) {

0 commit comments

Comments
 (0)