From 00c5a0426c41ee0c95d5bf0d7d94150c483511c8 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 29 Jun 2020 14:58:47 -0700 Subject: ... refactoring --- .../databind/deser/std/NumberDeserializers.java | 377 +++++++++++---------- .../databind/deser/std/StdDeserializer.java | 173 +++++----- 2 files changed, 287 insertions(+), 263 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java index 3b6be4f0a..3a7780391 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java @@ -603,25 +603,13 @@ public class NumberDeserializers protected final Long _parseLong(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return (Long) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Long) getEmptyValue(ctxt); - } - text = text.trim(); - if (_checkTextualNull(ctxt, text)) { - return (Long) getNullValue(ctxt); - } - // let's allow Strings to be converted too - return _parseLongPrimitive(ctxt, text); + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_FLOAT: - act = _checkFloatToIntCoercion(p, ctxt, _valueClass); + final CoercionAction act = _checkFloatToIntCoercion(p, ctxt, _valueClass); if (act == CoercionAction.AsNull) { return (Long) getNullValue(ctxt); } @@ -635,9 +623,23 @@ public class NumberDeserializers return p.getLongValue(); case JsonTokenId.ID_START_ARRAY: return (Long) _deserializeFromArray(p, ctxt); + default: + return (Long) ctxt.handleUnexpectedToken(getValueType(ctxt), p); } - // Otherwise, no can do: - return (Long) ctxt.handleUnexpectedToken(getValueType(ctxt), p); + + final CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Long) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Long) getEmptyValue(ctxt); + } + text = text.trim(); + if (_checkTextualNull(ctxt, text)) { + return (Long) getNullValue(ctxt); + } + // let's allow Strings to be converted too + return _parseLongPrimitive(ctxt, text); } } @@ -669,43 +671,11 @@ public class NumberDeserializers protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return (Float) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Float) getEmptyValue(ctxt); - } - text = text.trim(); - if (_checkTextualNull(ctxt, text)) { - return (Float) getNullValue(ctxt); - } - switch (text.charAt(0)) { - case 'I': - if (_isPosInf(text)) { - return Float.POSITIVE_INFINITY; - } - break; - case 'N': - if (_isNaN(text)) { - return Float.NaN; - } - break; - case '-': - if (_isNegInf(text)) { - return Float.NEGATIVE_INFINITY; - } - break; - } - try { - return Float.parseFloat(text); - } catch (IllegalArgumentException iae) { } - return (Float) ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid Float value"); + text = p.getText(); + break; case JsonTokenId.ID_NULL: // null fine for non-primitive return (Float) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_FLOAT: @@ -713,9 +683,42 @@ public class NumberDeserializers return p.getFloatValue(); case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); + default: + return (Float) ctxt.handleUnexpectedToken(_valueClass, p); + } + final CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Float) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Float) getEmptyValue(ctxt); + } + text = text.trim(); + if (_checkTextualNull(ctxt, text)) { + return (Float) getNullValue(ctxt); } - // Otherwise, no can do: - return (Float) ctxt.handleUnexpectedToken(_valueClass, p); + switch (text.charAt(0)) { + case 'I': + if (_isPosInf(text)) { + return Float.POSITIVE_INFINITY; + } + break; + case 'N': + if (_isNaN(text)) { + return Float.NaN; + } + break; + case '-': + if (_isNegInf(text)) { + return Float.NEGATIVE_INFINITY; + } + break; + } + try { + return Float.parseFloat(text); + } catch (IllegalArgumentException iae) { } + return (Float) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Float value"); } } @@ -760,43 +763,11 @@ public class NumberDeserializers protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return (Double) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Double) getEmptyValue(ctxt); - } - text = text.trim(); - if (_checkTextualNull(ctxt, text)) { - return (Double) getNullValue(ctxt); - } - switch (text.charAt(0)) { - case 'I': - if (_isPosInf(text)) { - return Double.POSITIVE_INFINITY; - } - break; - case 'N': - if (_isNaN(text)) { - return Double.NaN; - } - break; - case '-': - if (_isNegInf(text)) { - return Double.NEGATIVE_INFINITY; - } - break; - } - try { - return parseDouble(text); - } catch (IllegalArgumentException iae) { } - return (Double) ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid Double value"); + text = p.getText(); + break; case JsonTokenId.ID_NULL: // null fine for non-primitive return (Double) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_FLOAT: @@ -804,8 +775,44 @@ public class NumberDeserializers return p.getDoubleValue(); case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); + default: + return (Double) ctxt.handleUnexpectedToken(_valueClass, p); + } + + // Coercion from String most complicated + final CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Double) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Double) getEmptyValue(ctxt); + } + text = text.trim(); + if (_checkTextualNull(ctxt, text)) { + return (Double) getNullValue(ctxt); } - return (Double) ctxt.handleUnexpectedToken(_valueClass, p); + switch (text.charAt(0)) { + case 'I': + if (_isPosInf(text)) { + return Double.POSITIVE_INFINITY; + } + break; + case 'N': + if (_isNaN(text)) { + return Double.NaN; + } + break; + case '-': + if (_isNegInf(text)) { + return Double.NEGATIVE_INFINITY; + } + break; + } + try { + return _parseDouble(text); + } catch (IllegalArgumentException iae) { } + return (Double) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Double value"); } } @@ -839,7 +846,11 @@ public class NumberDeserializers @Override public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + String text; switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_INT: if (ctxt.hasSomeOfFeatures(F_MASK_INT_COERCIONS)) { return _coerceIntegral(p, ctxt); @@ -854,59 +865,56 @@ public class NumberDeserializers } } return p.getNumberValue(); + case JsonTokenId.ID_START_ARRAY: + return _deserializeFromArray(p, ctxt); + default: + return ctxt.handleUnexpectedToken(_valueClass, p); + } - case JsonTokenId.ID_STRING: - // Textual values are more difficult... not parsing itself, but figuring - // out 'minimal' type to use - - String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - // note: no need to call `coerce` as this is never primitive - return getNullValue(ctxt); - } - if (_isPosInf(text)) { - return Double.POSITIVE_INFINITY; - } - if (_isNegInf(text)) { - return Double.NEGATIVE_INFINITY; + // Textual values are more difficult... not parsing itself, but figuring + // out 'minimal' type to use + CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + // note: no need to call `coerce` as this is never primitive + return getNullValue(ctxt); + } + if (_isPosInf(text)) { + return Double.POSITIVE_INFINITY; + } + if (_isNegInf(text)) { + return Double.NEGATIVE_INFINITY; + } + if (_isNaN(text)) { + return Double.NaN; + } + try { + if (!_isIntNumber(text)) { + if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) { + return new BigDecimal(text); + } + return Double.valueOf(text); } - if (_isNaN(text)) { - return Double.NaN; + if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) { + return new BigInteger(text); } - try { - if (!_isIntNumber(text)) { - if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) { - return new BigDecimal(text); - } - return Double.valueOf(text); + long value = Long.parseLong(text); + if (!ctxt.isEnabled(DeserializationFeature.USE_LONG_FOR_INTS)) { + if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) { + return Integer.valueOf((int) value); } - if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) { - return new BigInteger(text); - } - long value = Long.parseLong(text); - if (!ctxt.isEnabled(DeserializationFeature.USE_LONG_FOR_INTS)) { - if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) { - return Integer.valueOf((int) value); - } - } - return Long.valueOf(value); - } catch (IllegalArgumentException iae) { - return ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid number"); } - case JsonTokenId.ID_START_ARRAY: - return _deserializeFromArray(p, ctxt); + return Long.valueOf(value); + } catch (IllegalArgumentException iae) { + return ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid number"); } - // Otherwise, no can do: - return ctxt.handleUnexpectedToken(_valueClass, p); } /** @@ -960,7 +968,6 @@ public class NumberDeserializers return LogicalType.Integer; } - @SuppressWarnings("incomplete-switch") @Override public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { @@ -968,10 +975,13 @@ public class NumberDeserializers return p.getBigIntegerValue(); } - CoercionAction act; + String text; switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: // let's do implicit re-parse + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_FLOAT: - act = _checkFloatToIntCoercion(p, ctxt, _valueClass); + final CoercionAction act = _checkFloatToIntCoercion(p, ctxt, _valueClass); if (act == CoercionAction.AsNull) { return (BigInteger) getNullValue(ctxt); } @@ -981,28 +991,28 @@ public class NumberDeserializers return p.getDecimalValue().toBigInteger(); case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); - case JsonTokenId.ID_STRING: // let's do implicit re-parse - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (BigInteger) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - // note: no need to call `coerce` as this is never primitive - return getNullValue(ctxt); - } - try { - return new BigInteger(text); - } catch (IllegalArgumentException iae) { } - return (BigInteger) ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid representation"); + default: + // String is ok too, can easily convert; otherwise, no can do: + return (BigInteger) ctxt.handleUnexpectedToken(_valueClass, p); + } + + final CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (BigInteger) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + // note: no need to call `coerce` as this is never primitive + return getNullValue(ctxt); } - // String is ok too, can easily convert; otherwise, no can do: - return (BigInteger) ctxt.handleUnexpectedToken(_valueClass, p); + try { + return new BigInteger(text); + } catch (IllegalArgumentException iae) { } + return (BigInteger) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid representation"); } } @@ -1029,34 +1039,37 @@ public class NumberDeserializers public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + String text; switch (p.currentTokenId()) { case JsonTokenId.ID_NUMBER_INT: case JsonTokenId.ID_NUMBER_FLOAT: return p.getDecimalValue(); case JsonTokenId.ID_STRING: - String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (BigDecimal) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - // note: no need to call `coerce` as this is never primitive - return getNullValue(ctxt); - } - try { - return new BigDecimal(text); - } catch (IllegalArgumentException iae) { } - return (BigDecimal) ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid representation"); + text = p.getText(); + break; case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); + default: + return (BigDecimal) ctxt.handleUnexpectedToken(_valueClass, p); + } + + final CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return getNullValue(ctxt); } - // Otherwise, no can do: - return (BigDecimal) ctxt.handleUnexpectedToken(_valueClass, p); + if (act == CoercionAction.AsEmpty) { + return (BigDecimal) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + // note: no need to call `coerce` as this is never primitive + return getNullValue(ctxt); + } + try { + return new BigDecimal(text); + } catch (IllegalArgumentException iae) { } + return (BigDecimal) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid representation"); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java index 963cbd235..4848e22b0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java @@ -725,31 +725,13 @@ public abstract class StdDeserializer protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { - case JsonTokenId.ID_NUMBER_INT: - return p.getLongValue(); - case JsonTokenId.ID_NULL: - _verifyNullForPrimitive(ctxt); - return 0L; case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, Long.TYPE); - if (act == CoercionAction.AsNull) { - return 0L; // no need to check as does not come from `null`, explicit coercion - } - if (act == CoercionAction.AsEmpty) { - return 0L; - } - text = text.trim(); - if (_hasTextualNull(text)) { - _verifyNullForPrimitiveCoercion(ctxt, text); - return 0L; - } - return _parseLongPrimitive(ctxt, text); + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_FLOAT: - act = _checkFloatToIntCoercion(p, ctxt, Long.TYPE); + final CoercionAction act = _checkFloatToIntCoercion(p, ctxt, Long.TYPE); if (act == CoercionAction.AsNull) { return 0L; } @@ -757,6 +739,11 @@ public abstract class StdDeserializer return 0L; } return p.getValueAsLong(); + case JsonTokenId.ID_NUMBER_INT: + return p.getLongValue(); + case JsonTokenId.ID_NULL: + _verifyNullForPrimitive(ctxt); + return 0L; case JsonTokenId.ID_START_ARRAY: if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { p.nextToken(); @@ -764,10 +751,25 @@ public abstract class StdDeserializer _verifyEndArrayForSingle(p, ctxt); return parsed; } - break; + // fall through default: + return ((Number) ctxt.handleUnexpectedToken(Long.TYPE, p)).longValue(); + } + + final CoercionAction act = _checkFromStringCoercion(ctxt, text, + LogicalType.Integer, Long.TYPE); + if (act == CoercionAction.AsNull) { + return 0L; // no need to check as does not come from `null`, explicit coercion } - return ((Number) ctxt.handleUnexpectedToken(Long.TYPE, p)).longValue(); + if (act == CoercionAction.AsEmpty) { + return 0L; + } + text = text.trim(); + if (_hasTextualNull(text)) { + _verifyNullForPrimitiveCoercion(ctxt, text); + return 0L; + } + return _parseLongPrimitive(ctxt, text); } /** @@ -788,30 +790,17 @@ public abstract class StdDeserializer protected final float _parseFloatPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_INT: case JsonTokenId.ID_NUMBER_FLOAT: return p.getFloatValue(); case JsonTokenId.ID_NULL: _verifyNullForPrimitive(ctxt); return 0f; - case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, Float.TYPE); - if (act == CoercionAction.AsNull) { - return 0.0f; // no need to check as does not come from `null`, explicit coercion - } - if (act == CoercionAction.AsEmpty) { - return 0.0f; - } - text = text.trim(); - if (_hasTextualNull(text)) { - _verifyNullForPrimitiveCoercion(ctxt, text); - return 0.0f; - } - return _parseFloatPrimitive(ctxt, text); case JsonTokenId.ID_START_ARRAY: if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { p.nextToken(); @@ -819,11 +808,26 @@ public abstract class StdDeserializer _verifyEndArrayForSingle(p, ctxt); return parsed; } - break; + // fall through + default: + return ((Number) ctxt.handleUnexpectedToken(Float.TYPE, p)).floatValue(); } - // Otherwise, no can do: - return ((Number) ctxt.handleUnexpectedToken(Float.TYPE, p)).floatValue(); - } + + final CoercionAction act = _checkFromStringCoercion(ctxt, text, + LogicalType.Integer, Float.TYPE); + if (act == CoercionAction.AsNull) { + return 0.0f; // no need to check as does not come from `null`, explicit coercion + } + if (act == CoercionAction.AsEmpty) { + return 0.0f; + } + text = text.trim(); + if (_hasTextualNull(text)) { + _verifyNullForPrimitiveCoercion(ctxt, text); + return 0.0f; + } + return _parseFloatPrimitive(ctxt, text); +} /** * @since 2.9 @@ -857,30 +861,17 @@ public abstract class StdDeserializer protected final double _parseDoublePrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { - CoercionAction act; + String text; switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_INT: case JsonTokenId.ID_NUMBER_FLOAT: return p.getDoubleValue(); case JsonTokenId.ID_NULL: _verifyNullForPrimitive(ctxt); return 0.0; - case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, Double.TYPE); - if (act == CoercionAction.AsNull) { - return 0.0; // no need to check as does not come from `null`, explicit coercion - } - if (act == CoercionAction.AsEmpty) { - return 0.0; - } - text = text.trim(); - if (_hasTextualNull(text)) { - _verifyNullForPrimitiveCoercion(ctxt, text); - return 0.0; - } - return _parseDoublePrimitive(ctxt, text); case JsonTokenId.ID_START_ARRAY: if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { p.nextToken(); @@ -888,10 +879,25 @@ public abstract class StdDeserializer _verifyEndArrayForSingle(p, ctxt); return parsed; } - break; + // fall through + default: + return ((Number) ctxt.handleUnexpectedToken(Double.TYPE, p)).doubleValue(); } - // Otherwise, no can do: - return ((Number) ctxt.handleUnexpectedToken(Double.TYPE, p)).doubleValue(); + + final CoercionAction act = _checkFromStringCoercion(ctxt, text, + LogicalType.Integer, Double.TYPE); + if (act == CoercionAction.AsNull) { + return 0.0; // no need to check as does not come from `null`, explicit coercion + } + if (act == CoercionAction.AsEmpty) { + return 0.0; + } + text = text.trim(); + if (_hasTextualNull(text)) { + _verifyNullForPrimitiveCoercion(ctxt, text); + return 0.0; + } + return _parseDoublePrimitive(ctxt, text); } /** @@ -918,19 +924,34 @@ public abstract class StdDeserializer break; } try { - return parseDouble(text); + return _parseDouble(text); } catch (IllegalArgumentException iae) { } Number v = (Number) ctxt.handleWeirdStringValue(Double.TYPE, text, "not a valid `double` value (as String to convert)"); return _nonNullNumber(v).doubleValue(); } + /** + * Helper method for encapsulating calls to low-level double value parsing; single place + * just because we need a work-around that must be applied to all calls. + */ + protected final static double _parseDouble(String numStr) throws NumberFormatException + { + // avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE? + if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) { + return Double.MIN_NORMAL; // since 2.7; was MIN_VALUE prior + } + return Double.parseDouble(numStr); + } + protected java.util.Date _parseDate(JsonParser p, DeserializationContext ctxt) throws IOException { + String text; switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - return _parseDate(p.getText().trim(), ctxt); + text = p.getText(); + break; case JsonTokenId.ID_NUMBER_INT: { long ts; @@ -949,8 +970,11 @@ public abstract class StdDeserializer return (java.util.Date) getNullValue(ctxt); case JsonTokenId.ID_START_ARRAY: return _parseDateFromArray(p, ctxt); + default: + return (java.util.Date) ctxt.handleUnexpectedToken(_valueClass, p); } - return (java.util.Date) ctxt.handleUnexpectedToken(_valueClass, p); + + return _parseDate(text.trim(), ctxt); } // @since 2.9 @@ -1011,19 +1035,6 @@ public abstract class StdDeserializer } } - /** - * Helper method for encapsulating calls to low-level double value parsing; single place - * just because we need a work-around that must be applied to all calls. - */ - protected final static double parseDouble(String numStr) throws NumberFormatException - { - // avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE? - if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) { - return Double.MIN_NORMAL; // since 2.7; was MIN_VALUE prior - } - return Double.parseDouble(numStr); - } - /** * Helper method used for accessing String value, if possible, doing * necessary conversion or throwing exception as necessary. -- cgit v1.2.3