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 1116058329..003bc7ae05 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 @@ -828,29 +828,6 @@ protected CoercionAction _checkFromStringCoercion(DeserializationContext ctxt, S /* Helper methods for sub-classes, coercions, older (pre-2.12) /**************************************************** */ - /** - * Method called when JSON String with value "" (that is, zero length) is encountered. - * - * @deprecated Since 2.12 - */ - @Deprecated - protected Object _coerceEmptyString(DeserializationContext ctxt, boolean isPrimitive) throws JsonMappingException - { - Enum feat; - boolean enable; - - if (!ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)) { - feat = MapperFeature.ALLOW_COERCION_OF_SCALARS; - enable = true; - } else if (isPrimitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) { - feat = DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES; - enable = false; - } else { - return getNullValue(ctxt); - } - _reportFailedNullCoerce(ctxt, enable, feat, "empty String (\"\")"); - return null; - } protected void _failDoubleToIntCoercion(JsonParser p, DeserializationContext ctxt, String type) throws IOException diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalDoubleDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalDoubleDeserializer.java index 00033a96fc..47d9900cb4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalDoubleDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalDoubleDeserializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonTokenId; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.cfg.CoercionAction; import com.fasterxml.jackson.databind.type.LogicalType; public class OptionalDoubleDeserializer extends BaseScalarOptionalDeserializer @@ -29,16 +30,22 @@ public OptionalDouble deserialize(JsonParser p, DeserializationContext ctxt) thr } switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText().trim(); - if ((text.length() == 0)) { - _coerceEmptyString(ctxt, false); - return _empty; + { + String text = p.getText(); + CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (OptionalDouble) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (OptionalDouble) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + _coerceTextualNull(ctxt, false); + return _empty; + } + return OptionalDouble.of(_parseDoublePrimitive(ctxt, text)); } - if (_hasTextualNull(text)) { - _coerceTextualNull(ctxt, false); - return _empty; - } - return OptionalDouble.of(_parseDoublePrimitive(ctxt, text)); case JsonTokenId.ID_NUMBER_INT: // coercion here should be fine return OptionalDouble.of(p.getDoubleValue()); case JsonTokenId.ID_NULL: diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalIntDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalIntDeserializer.java index 4f6f78e21a..ef64522e5f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalIntDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalIntDeserializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonTokenId; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.cfg.CoercionAction; import com.fasterxml.jackson.databind.type.LogicalType; public class OptionalIntDeserializer extends BaseScalarOptionalDeserializer @@ -29,16 +30,22 @@ public OptionalInt deserialize(JsonParser p, DeserializationContext ctxt) throws } switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText().trim(); - if ((text.length() == 0)) { - _coerceEmptyString(ctxt, false); - return _empty; + { + String text = p.getText(); + CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (OptionalInt) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (OptionalInt) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + _coerceTextualNull(ctxt, false); + return _empty; + } + return OptionalInt.of(_parseIntPrimitive(ctxt, text)); } - if (_hasTextualNull(text)) { - _coerceTextualNull(ctxt, false); - return _empty; - } - return OptionalInt.of(_parseIntPrimitive(ctxt, text)); case JsonTokenId.ID_NUMBER_FLOAT: if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) { _failDoubleToIntCoercion(p, ctxt, "int"); diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalLongDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalLongDeserializer.java index a8c9e661d0..38d0ab7168 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalLongDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/jdk8/OptionalLongDeserializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonTokenId; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.cfg.CoercionAction; import com.fasterxml.jackson.databind.type.LogicalType; public class OptionalLongDeserializer extends BaseScalarOptionalDeserializer @@ -30,16 +31,22 @@ public OptionalLong deserialize(JsonParser p, DeserializationContext ctxt) throw } switch (p.currentTokenId()) { case JsonTokenId.ID_STRING: - String text = p.getText().trim(); - if ((text.length() == 0)) { - _coerceEmptyString(ctxt, false); - return _empty; + { + String text = p.getText(); + CoercionAction act = _checkFromStringCoercion(ctxt, text); + if (act == CoercionAction.AsNull) { + return (OptionalLong) getNullValue(ctxt); + } + if (act == CoercionAction.AsEmpty) { + return (OptionalLong) getEmptyValue(ctxt); + } + text = text.trim(); + if (_hasTextualNull(text)) { + _coerceTextualNull(ctxt, false); + return _empty; + } + return OptionalLong.of(_parseLongPrimitive(ctxt, text)); } - if (_hasTextualNull(text)) { - _coerceTextualNull(ctxt, false); - return _empty; - } - return OptionalLong.of(_parseLongPrimitive(ctxt, text)); case JsonTokenId.ID_NUMBER_FLOAT: if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) { _failDoubleToIntCoercion(p, ctxt, "long");