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 d6a6589c9a..2eba63bdc3 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 @@ -314,8 +314,8 @@ protected Byte _parseByte(DeserializationContext ctxt, JsonParser p) return (Byte) getEmptyValue(ctxt); } return p.getByteValue(); - case JsonTokenId.ID_NULL: - return (Byte) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Byte) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_INT: return p.getByteValue(); case JsonTokenId.ID_START_ARRAY: @@ -392,8 +392,8 @@ protected Short _parseShort(DeserializationContext ctxt, JsonParser p) return (Short) getEmptyValue(ctxt); } return p.getShortValue(); - case JsonTokenId.ID_NULL: - return (Short) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Short) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_INT: return p.getShortValue(); case JsonTokenId.ID_START_ARRAY: @@ -455,7 +455,10 @@ public Character deserialize(JsonParser p, DeserializationContext ctxt) } break; case JsonTokenId.ID_NULL: - return (Character) _coerceNullToken(ctxt, _primitive); + if (_primitive) { + _verifyNullForPrimitive(ctxt); + } + return (Character) getNullValue(ctxt); case JsonTokenId.ID_START_ARRAY: return _deserializeFromArray(p, ctxt); default: @@ -553,8 +556,8 @@ protected final Integer _parseInteger(DeserializationContext ctxt, JsonParser p) 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_NULL: // null fine for non-primitive + return (Integer) getNullValue(ctxt); case JsonTokenId.ID_START_ARRAY: return (Integer) _deserializeFromArray(p, ctxt); } @@ -624,8 +627,8 @@ protected final Long _parseLong(DeserializationContext ctxt, JsonParser p) return (Long) getEmptyValue(ctxt); } return p.getValueAsLong(); - case JsonTokenId.ID_NULL: - return (Long) _coerceNullToken(ctxt, false); + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Long) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_INT: return p.getLongValue(); case JsonTokenId.ID_START_ARRAY: @@ -701,8 +704,8 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt) } catch (IllegalArgumentException iae) { } return (Float) ctxt.handleWeirdStringValue(_valueClass, text, "not a valid Float value"); - case JsonTokenId.ID_NULL: - return (Float) _coerceNullToken(ctxt, _primitive); + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Float) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_FLOAT: case JsonTokenId.ID_NUMBER_INT: // safe coercion return p.getFloatValue(); @@ -792,8 +795,8 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t } catch (IllegalArgumentException iae) { } return (Double) ctxt.handleWeirdStringValue(_valueClass, text, "not a valid Double value"); - case JsonTokenId.ID_NULL: - return (Double) _coerceNullToken(ctxt, _primitive); + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Double) getNullValue(ctxt); case JsonTokenId.ID_NUMBER_FLOAT: case JsonTokenId.ID_NUMBER_INT: // safe coercion return p.getDoubleValue(); 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 9dc7f73112..1512921282 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 @@ -431,15 +431,6 @@ protected final Boolean _parseBoolean(DeserializationContext ctxt, throws IOException { switch (p.currentTokenId()) { - case JsonTokenId.ID_TRUE: - return true; - case JsonTokenId.ID_FALSE: - return false; - case JsonTokenId.ID_NULL: - return (Boolean) _coerceNullToken(ctxt, false); - case JsonTokenId.ID_NUMBER_INT: - // may accept ints too, (0 == false, otherwise true) - return _coerceBooleanFromInt(ctxt, p, targetType); case JsonTokenId.ID_STRING: String text = p.getText(); CoercionAction act = _checkFromStringCoercion(ctxt, text, @@ -463,6 +454,15 @@ protected final Boolean _parseBoolean(DeserializationContext ctxt, } return (Boolean) ctxt.handleWeirdStringValue(_valueClass, text, "only \"true\" or \"false\" recognized"); + case JsonTokenId.ID_TRUE: + return true; + case JsonTokenId.ID_FALSE: + return false; + case JsonTokenId.ID_NULL: // null fine for non-primitive + return (Boolean) getNullValue(ctxt); + case JsonTokenId.ID_NUMBER_INT: + // may accept ints too, (0 == false, otherwise true) + return _coerceBooleanFromInt(ctxt, p, targetType); case JsonTokenId.ID_START_ARRAY: // unwrapping / from-empty-array coercion? return (Boolean) _deserializeFromArray(p, ctxt); } @@ -1211,20 +1211,6 @@ protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) thro return p.getNumberValue(); // should be optimal, whatever it is } - /** - * Method to call when JSON `null` token is encountered. Note: only called when - * this deserializer encounters it but NOT when reached via property - * - * @since 2.9 - */ - protected Object _coerceNullToken(DeserializationContext ctxt, boolean isPrimitive) throws JsonMappingException - { - if (isPrimitive) { - _verifyNullForPrimitive(ctxt); - } - return getNullValue(ctxt); - } - /** * Method called when JSON String with value "null" is encountered. * @@ -1389,6 +1375,15 @@ protected void _verifyNumberForScalarCoercion(DeserializationContext ctxt, JsonP } } + @Deprecated // since 2.12 + protected Object _coerceNullToken(DeserializationContext ctxt, boolean isPrimitive) throws JsonMappingException + { + if (isPrimitive) { + _verifyNullForPrimitive(ctxt); + } + return getNullValue(ctxt); + } + /* /**************************************************** /* Helper methods for sub-classes, resolving dependencies