diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/AtomicBooleanDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/AtomicBooleanDeserializer.java index 282fb27139..6f2eeb4cae 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/AtomicBooleanDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/AtomicBooleanDeserializer.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.type.LogicalType; public class AtomicBooleanDeserializer extends StdScalarDeserializer @@ -31,4 +32,9 @@ public AtomicBoolean deserialize(JsonParser p, DeserializationContext ctxt) thro @Override public LogicalType logicalType() { return LogicalType.Boolean; } -} \ No newline at end of file + + @Override // @since 2.12 + public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException { + return new AtomicBoolean(false); + } +} 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 7cba05f7c2..a16893f590 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 @@ -6,6 +6,7 @@ import java.util.HashSet; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.io.NumberInput; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.cfg.CoercionAction; @@ -268,7 +269,59 @@ public Byte deserialize(JsonParser p, DeserializationContext ctxt) throws IOExce if (_primitive) { return _parseBytePrimitive(ctxt, p); } - return _parseByte(ctxt, p, _valueClass); + return _parseByte(ctxt, p); + } + + protected Byte _parseByte(DeserializationContext ctxt, JsonParser p) + throws IOException + { + CoercionAction act; + switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: // let's do implicit re-parse + String text = p.getText(); + act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Byte) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Byte) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + return (Byte) _coerceTextualNull(ctxt, false); + } + int value; + try { + value = NumberInput.parseInt(text); + } catch (IllegalArgumentException iae) { + return (Byte) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Byte value"); + } + // So far so good: but does it fit? + // as per [JACKSON-804], allow range up to 255, inclusive + if (_byteOverflow(value)) { + return (Byte) ctxt.handleWeirdStringValue(_valueClass, text, + "overflow, value cannot be represented as 8-bit value"); + // fall-through for deferred fails + } + return Byte.valueOf((byte) value); + case JsonTokenId.ID_NUMBER_FLOAT: + act = _checkFloatToIntCoercion(ctxt, p, _valueClass); + if (act == CoercionAction.AsNull) { + return (Byte) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Byte) getEmptyValue(ctxt); + } + return p.getByteValue(); + case JsonTokenId.ID_NULL: + return (Byte) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NUMBER_INT: + return p.getByteValue(); + case JsonTokenId.ID_START_ARRAY: + return (Byte) _deserializeFromArray(p, ctxt); + } + return (Byte) ctxt.handleUnexpectedToken(getValueType(ctxt), p); } } @@ -296,7 +349,57 @@ public Short deserialize(JsonParser p, DeserializationContext ctxt) if (_primitive) { return _parseShortPrimitive(ctxt, p); } - return _parseShort(ctxt, p, _valueClass); + return _parseShort(ctxt, p); + } + + protected Short _parseShort(DeserializationContext ctxt, JsonParser p) + throws IOException + { + CoercionAction act; + switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: // let's do implicit re-parse + String text = p.getText(); + act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Short) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Short) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + return (Short) _coerceTextualNull(ctxt, false); + } + int value; + try { + value = NumberInput.parseInt(text); + } catch (IllegalArgumentException iae) { + return (Short) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Short value"); + } + // So far so good: but does it fit? + if (_shortOverflow(value)) { + return (Short) ctxt.handleWeirdStringValue(_valueClass, text, + "overflow, value cannot be represented as 16-bit value"); + } + return (short) value; + case JsonTokenId.ID_NUMBER_FLOAT: + act = _checkFloatToIntCoercion(ctxt, p, _valueClass); + if (act == CoercionAction.AsNull) { + return (Short) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Short) getEmptyValue(ctxt); + } + return p.getShortValue(); + case JsonTokenId.ID_NULL: + return (Short) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NUMBER_INT: + return p.getShortValue(); + case JsonTokenId.ID_START_ARRAY: + return (Short)_deserializeFromArray(p, ctxt); + } + return (Short) ctxt.handleUnexpectedToken(getValueType(ctxt), p); } } @@ -386,7 +489,7 @@ public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOE if (_primitive) { return _parseIntPrimitive(ctxt, p); } - return _parseInteger(ctxt, p, _valueClass); + return _parseInteger(ctxt, p); } // Since we can never have type info ("natural type"; String, Boolean, Integer, Double): @@ -401,7 +504,61 @@ public Integer deserializeWithType(JsonParser p, DeserializationContext ctxt, if (_primitive) { return _parseIntPrimitive(ctxt, p); } - return _parseInteger(ctxt, p, _valueClass); + return _parseInteger(ctxt, p); + } + + // @since 2.12 + protected final Integer _parseInteger(DeserializationContext ctxt, JsonParser p) + throws IOException + { + CoercionAction act; + switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: // let's do implicit re-parse + String text = p.getText(); + act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (Integer) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Integer) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + return (Integer) _coerceTextualNull(ctxt, false); + } + final int len = text.length(); + try { + if (len > 9) { + long l = Long.parseLong(text); + if (_intOverflow(l)) { + return (Integer) ctxt.handleWeirdStringValue(_valueClass, text, String.format( + "Overflow: numeric value (%s) out of range of Integer (%d - %d)", + text, Integer.MIN_VALUE, Integer.MAX_VALUE)); + } + return Integer.valueOf((int) l); + } + return Integer.valueOf(NumberInput.parseInt(text)); + } catch (IllegalArgumentException iae) { + return (Integer) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Integer value"); + } + case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too + act = _checkFloatToIntCoercion(ctxt, p, _valueClass); + if (act == CoercionAction.AsNull) { + return (Integer) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Integer) getEmptyValue(ctxt); + } + return p.getValueAsInt(); + case JsonTokenId.ID_NUMBER_INT: // NOTE: caller assumed to check in fast path + return p.getIntValue(); + case JsonTokenId.ID_NULL: + return (Integer) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_START_ARRAY: + return (Integer) _deserializeFromArray(p, ctxt); + } + return (Integer) ctxt.handleUnexpectedToken(getValueType(ctxt), p); } } @@ -430,7 +587,52 @@ public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOExce if (_primitive) { return _parseLongPrimitive(ctxt, p); } - return _parseLong(ctxt, p, _valueClass); + return _parseLong(ctxt, p); + } + + // @since 2.12 + protected final Long _parseLong(DeserializationContext ctxt, JsonParser p) + throws IOException + { + CoercionAction act; + 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 (_hasTextualNull(text)) { + return (Long) _coerceTextualNull(ctxt, false); + } + // let's allow Strings to be converted too + try { + return Long.valueOf(NumberInput.parseLong(text)); + } catch (IllegalArgumentException iae) { } + return (Long) ctxt.handleWeirdStringValue(_valueClass, text, + "not a valid Long value"); + case JsonTokenId.ID_NUMBER_FLOAT: + act = _checkFloatToIntCoercion(ctxt, p, _valueClass); + if (act == CoercionAction.AsNull) { + return (Long) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (Long) getEmptyValue(ctxt); + } + return p.getValueAsLong(); + case JsonTokenId.ID_NULL: + return (Long) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NUMBER_INT: + return p.getLongValue(); + case JsonTokenId.ID_START_ARRAY: + return (Long) _deserializeFromArray(p, ctxt); + } + // Otherwise, no can do: + return (Long) ctxt.handleUnexpectedToken(getValueType(ctxt), p); } } @@ -450,6 +652,9 @@ public FloatDeserializer(Class cls, Float nvl) { @Override public Float deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + if (p.hasToken(JsonToken.VALUE_NUMBER_FLOAT)) { + return p.getFloatValue(); + } if (_primitive) { return _parseFloatPrimitive(ctxt, p); } @@ -459,18 +664,11 @@ public Float deserialize(JsonParser p, DeserializationContext ctxt) throws IOExc protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt) throws IOException { - // We accept couple of different types; obvious ones first: - if (p.hasToken(JsonToken.VALUE_NUMBER_FLOAT)) { - return p.getFloatValue(); - } - final JsonToken t = p.currentToken(); - if (t == JsonToken.VALUE_NUMBER_INT) { // safe coercion - return p.getFloatValue(); - } - // And finally, let's allow Strings to be converted too - if (t == JsonToken.VALUE_STRING) { + CoercionAction act; + switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text); + act = _checkFromStringCoercion(ctxt, text); if (act == CoercionAction.AsNull) { return (Float) getNullValue(ctxt); } @@ -479,7 +677,7 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt) } text = text.trim(); if (_hasTextualNull(text)) { - return (Float) _coerceTextualNull(ctxt, _primitive); + return (Float) _coerceTextualNull(ctxt, false); } switch (text.charAt(0)) { case 'I': @@ -503,11 +701,12 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt) } catch (IllegalArgumentException iae) { } return (Float) ctxt.handleWeirdStringValue(_valueClass, text, "not a valid Float value"); - } - if (t == JsonToken.VALUE_NULL) { + case JsonTokenId.ID_NULL: return (Float) _coerceNullToken(ctxt, _primitive); - } - if (t == JsonToken.START_ARRAY) { + case JsonTokenId.ID_NUMBER_FLOAT: + case JsonTokenId.ID_NUMBER_INT: // safe coercion + return p.getFloatValue(); + case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); } // Otherwise, no can do: @@ -530,6 +729,12 @@ public DoubleDeserializer(Class cls, Double nvl) { @Override public Double deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + if (p.hasToken(JsonToken.VALUE_NUMBER_FLOAT)) { + return p.getDoubleValue(); + } + if (_primitive) { + return _parseDoublePrimitive(ctxt, p); + } return _parseDouble(p, ctxt); } @@ -539,6 +744,9 @@ public Double deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx public Double deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException { + if (p.hasToken(JsonToken.VALUE_NUMBER_FLOAT)) { + return p.getDoubleValue(); + } if (_primitive) { return _parseDoublePrimitive(ctxt, p); } @@ -547,17 +755,11 @@ public Double deserializeWithType(JsonParser p, DeserializationContext ctxt, protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) throws IOException { - // We accept couple of different types; obvious ones first: - if (p.hasToken(JsonToken.VALUE_NUMBER_FLOAT)) { - return p.getDoubleValue(); - } - final JsonToken t = p.currentToken(); - if (t == JsonToken.VALUE_NUMBER_INT) { // safe coercion - return p.getDoubleValue(); - } - if (t == JsonToken.VALUE_STRING) { + CoercionAction act; + switch (p.currentTokenId()) { + case JsonTokenId.ID_STRING: String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text); + act = _checkFromStringCoercion(ctxt, text); if (act == CoercionAction.AsNull) { return (Double) getNullValue(ctxt); } @@ -590,14 +792,14 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t } catch (IllegalArgumentException iae) { } return (Double) ctxt.handleWeirdStringValue(_valueClass, text, "not a valid Double value"); - } - if (t == JsonToken.VALUE_NULL) { + case JsonTokenId.ID_NULL: return (Double) _coerceNullToken(ctxt, _primitive); - } - if (t == JsonToken.START_ARRAY) { + case JsonTokenId.ID_NUMBER_FLOAT: + case JsonTokenId.ID_NUMBER_INT: // safe coercion + return p.getDoubleValue(); + case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); } - // Otherwise, no can do: return (Double) ctxt.handleUnexpectedToken(_valueClass, p); } } 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 13f7b660c8..80df791426 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 @@ -401,6 +401,7 @@ protected final boolean _parseBooleanPrimitive(DeserializationContext ctxt, } text = text.trim(); // [databind#422]: Allow aliases + // 13-Jun-2020, tatu: ... should we consider "lenient" vs "strict" here? if ("true".equals(text) || "True".equals(text)) { return true; } @@ -429,19 +430,17 @@ protected final Boolean _parseBoolean(DeserializationContext ctxt, JsonParser p, Class targetType) throws IOException { - final JsonToken t = p.currentToken(); - // usually caller should have handled but: - if (t == JsonToken.VALUE_TRUE) return true; - if (t == JsonToken.VALUE_FALSE) return false; - if (t == JsonToken.VALUE_NULL) { + switch (p.currentTokenId()) { + case JsonTokenId.ID_TRUE: + return true; + case JsonTokenId.ID_FALSE: + return false; + case JsonTokenId.ID_NULL: return (Boolean) _coerceNullToken(ctxt, false); - } - // may accept ints too, (0 == false, otherwise true) - if (t == JsonToken.VALUE_NUMBER_INT) { + case JsonTokenId.ID_NUMBER_INT: + // may accept ints too, (0 == false, otherwise true) return _coerceBooleanFromInt(ctxt, p, targetType); - } - // And finally, let's allow Strings to be converted too - if (t == JsonToken.VALUE_STRING) { + case JsonTokenId.ID_STRING: String text = p.getText(); CoercionAction act = _checkFromStringCoercion(ctxt, text, LogicalType.Boolean, targetType); @@ -464,8 +463,7 @@ protected final Boolean _parseBoolean(DeserializationContext ctxt, } return (Boolean) ctxt.handleWeirdStringValue(_valueClass, text, "only \"true\" or \"false\" recognized"); - } - if (t == JsonToken.START_ARRAY) { // unwrapping / from-empty-array coercion? + case JsonTokenId.ID_START_ARRAY: // unwrapping / from-empty-array coercion? return (Boolean) _deserializeFromArray(p, ctxt); } // Otherwise, no can do: @@ -554,63 +552,6 @@ protected final byte _parseBytePrimitive(DeserializationContext ctxt, JsonParser return ((Byte) ctxt.handleUnexpectedToken(ctxt.constructType(Byte.TYPE), p)).byteValue(); } - /** - * @since 2.12 - */ - protected Byte _parseByte(DeserializationContext ctxt, JsonParser p, - Class targetType) throws IOException - { - final JsonToken t = p.currentToken(); - if (t == JsonToken.VALUE_NUMBER_INT) return p.getByteValue(); - if (t == JsonToken.VALUE_NULL) { - return (Byte) _coerceNullToken(ctxt, false); - } - if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse - String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, targetType); - if (act == CoercionAction.AsNull) { - return (Byte) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Byte) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - return (Byte) _coerceTextualNull(ctxt, false); - } - int value; - try { - value = NumberInput.parseInt(text); - } catch (IllegalArgumentException iae) { - return (Byte) ctxt.handleWeirdStringValue(targetType, text, - "not a valid Byte value"); - } - // So far so good: but does it fit? - // as per [JACKSON-804], allow range up to 255, inclusive - if (_byteOverflow(value)) { - return (Byte) ctxt.handleWeirdStringValue(targetType, text, - "overflow, value cannot be represented as 8-bit value"); - // fall-through for deferred fails - } - return Byte.valueOf((byte) value); - } - if (t == JsonToken.VALUE_NUMBER_FLOAT) { - CoercionAction act = _checkFloatToIntCoercion(ctxt, p, targetType); - if (act == CoercionAction.AsNull) { - return (Byte) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Byte) getEmptyValue(ctxt); - } - return p.getByteValue(); - } - if (t == JsonToken.START_ARRAY) { // [databind#381] - return (Byte) _deserializeFromArray(p, ctxt); - } - return (Byte) ctxt.handleUnexpectedToken(ctxt.constructType(targetType), p); - } - @Deprecated // since 2.12, use overloaded variant protected final short _parseShortPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { return _parseShortPrimitive(ctxt, p); @@ -676,57 +617,6 @@ protected final short _parseShortPrimitive(DeserializationContext ctxt, JsonPars return ((Short) ctxt.handleUnexpectedToken(ctxt.constructType(Short.TYPE), p)).shortValue(); } - protected Short _parseShort(DeserializationContext ctxt, JsonParser p, - Class targetType) throws IOException - { - final JsonToken t = p.currentToken(); - if (t == JsonToken.VALUE_NUMBER_INT) return p.getShortValue(); - if (t == JsonToken.VALUE_NULL) { - return (Short) _coerceNullToken(ctxt, false); - } - if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse - String text = p.getText(); - CoercionAction act = _checkFromStringCoercion(ctxt, text); - if (act == CoercionAction.AsNull) { - return (Short) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Short) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - return (Short) _coerceTextualNull(ctxt, false); - } - int value; - try { - value = NumberInput.parseInt(text); - } catch (IllegalArgumentException iae) { - return (Short) ctxt.handleWeirdStringValue(_valueClass, text, - "not a valid Short value"); - } - // So far so good: but does it fit? - if (_shortOverflow(value)) { - return (Short) ctxt.handleWeirdStringValue(_valueClass, text, - "overflow, value cannot be represented as 16-bit value"); - } - return (short) value; - } - if (t == JsonToken.VALUE_NUMBER_FLOAT) { - CoercionAction act = _checkFloatToIntCoercion(ctxt, p, targetType); - if (act == CoercionAction.AsNull) { - return (Short) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Short) getEmptyValue(ctxt); - } - return p.getShortValue(); - } - if (t == JsonToken.START_ARRAY) { - return (Short)_deserializeFromArray(p, ctxt); - } - return (Short) ctxt.handleUnexpectedToken(ctxt.constructType(targetType), p); - } - @Deprecated // since 2.12, use overloaded variant protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { return _parseIntPrimitive(ctxt, p); @@ -805,63 +695,6 @@ protected final int _parseIntPrimitive(DeserializationContext ctxt, String text) } } - // @since 2.12 - protected final Integer _parseInteger(DeserializationContext ctxt, JsonParser p, - Class targetType) throws IOException - { - CoercionAction act; - switch (p.currentTokenId()) { - // NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path - case JsonTokenId.ID_NUMBER_INT: - return p.getIntValue(); - case JsonTokenId.ID_NULL: - return (Integer) _coerceNullToken(ctxt, false); - case JsonTokenId.ID_STRING: // let's do implicit re-parse - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, targetType); - if (act == CoercionAction.AsNull) { - return (Integer) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Integer) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - return (Integer) _coerceTextualNull(ctxt, false); - } - final int len = text.length(); - try { - if (len > 9) { - long l = Long.parseLong(text); - if (_intOverflow(l)) { - return (Integer) ctxt.handleWeirdStringValue(targetType, text, String.format( - "Overflow: numeric value (%s) out of range of Integer (%d - %d)", - text, Integer.MIN_VALUE, Integer.MAX_VALUE)); - } - return Integer.valueOf((int) l); - } - return Integer.valueOf(NumberInput.parseInt(text)); - } catch (IllegalArgumentException iae) { - return (Integer) ctxt.handleWeirdStringValue(targetType, text, - "not a valid Integer value"); - } - case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too - act = _checkFloatToIntCoercion(ctxt, p, targetType); - if (act == CoercionAction.AsNull) { - return (Integer) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Integer) getEmptyValue(ctxt); - } - return p.getValueAsInt(); - case JsonTokenId.ID_START_ARRAY: - return (Integer) _deserializeFromArray(p, ctxt); - } - // Otherwise, no can do: - return (Integer) ctxt.handleUnexpectedToken(ctxt.constructType(targetType), p); - } - @Deprecated // since 2.12, use overloaded variant protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException { @@ -931,53 +764,6 @@ protected final long _parseLongPrimitive(DeserializationContext ctxt, String tex } } - // @since 2.12 - protected final Long _parseLong(DeserializationContext ctxt, JsonParser p, - Class targetType) throws IOException - { - CoercionAction act; - switch (p.currentTokenId()) { - // NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path - case JsonTokenId.ID_NUMBER_INT: - return p.getLongValue(); - case JsonTokenId.ID_NULL: - return (Long) _coerceNullToken(ctxt, false); - case JsonTokenId.ID_STRING: - String text = p.getText(); - act = _checkFromStringCoercion(ctxt, text, - LogicalType.Integer, targetType); - if (act == CoercionAction.AsNull) { - return (Long) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Long) getEmptyValue(ctxt); - } - text = text.trim(); - if (_hasTextualNull(text)) { - return (Long) _coerceTextualNull(ctxt, false); - } - // let's allow Strings to be converted too - try { - return Long.valueOf(NumberInput.parseLong(text)); - } catch (IllegalArgumentException iae) { } - return (Long) ctxt.handleWeirdStringValue(targetType, text, - "not a valid Long value"); - case JsonTokenId.ID_NUMBER_FLOAT: - act = _checkFloatToIntCoercion(ctxt, p, targetType); - if (act == CoercionAction.AsNull) { - return (Long) getNullValue(ctxt); - } - if (act == CoercionAction.AsEmpty) { - return (Long) getEmptyValue(ctxt); - } - return p.getValueAsLong(); - case JsonTokenId.ID_START_ARRAY: - return (Long) _deserializeFromArray(p, ctxt); - } - // Otherwise, no can do: - return (Long) ctxt.handleUnexpectedToken(ctxt.constructType(targetType), p); - } - @Deprecated // since 2.12, use overloaded variant protected final float _parseFloatPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException {