Skip to content

Commit

Permalink
Merge branch '2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 13, 2020
2 parents d19be52 + e6e73d6 commit 32a38ee
Showing 5 changed files with 53 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -274,8 +274,8 @@ protected Byte _parseByte(DeserializationContext ctxt, JsonParser p)
return (Byte) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Byte) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Byte) getNullValue(ctxt);
}
int value;
try {
@@ -352,8 +352,8 @@ protected Short _parseShort(DeserializationContext ctxt, JsonParser p)
return (Short) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Short) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Short) getNullValue(ctxt);
}
int value;
try {
@@ -429,8 +429,8 @@ public Character deserialize(JsonParser p, DeserializationContext ctxt)
return (Character) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Character) _coerceTextualNull(ctxt, _primitive);
if (_checkTextualNull(ctxt, text)) {
return (Character) getNullValue(ctxt);
}
// But does it have to be exactly one char?
if (text.length() == 1) {
@@ -505,8 +505,8 @@ protected final Integer _parseInteger(DeserializationContext ctxt, JsonParser p)
return (Integer) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Integer) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Integer) getNullValue(ctxt);
}
final int len = text.length();
try {
@@ -584,8 +584,8 @@ protected final Long _parseLong(DeserializationContext ctxt, JsonParser p)
return (Long) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Long) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Long) getNullValue(ctxt);
}
// let's allow Strings to be converted too
try {
@@ -652,8 +652,8 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt)
return (Float) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Float) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Float) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
@@ -741,8 +741,8 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t
return (Double) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Double) _coerceTextualNull(ctxt, _primitive);
if (_checkTextualNull(ctxt, text)) {
return (Double) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ protected final boolean _parseBooleanPrimitive(DeserializationContext ctxt,
return ((Boolean) ctxt.handleUnexpectedToken(ctxt.constructType(Boolean.TYPE), p)).booleanValue();
}

protected final Boolean _parseBoolean(DeserializationContext ctxt,
protected final Boolean _parseBoolean(DeserializationContext ctxt,
JsonParser p, Class<?> targetType)
throws IOException
{
@@ -390,8 +390,8 @@ protected final Boolean _parseBoolean(DeserializationContext ctxt,
if ("false".equals(text) || "False".equals(text)) {
return Boolean.FALSE;
}
if (_hasTextualNull(text)) {
return (Boolean) _coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return (Boolean) getNullValue(ctxt);
}
return (Boolean) ctxt.handleWeirdStringValue(_valueClass, text,
"only \"true\" or \"false\" recognized");
@@ -528,11 +528,6 @@ protected final short _parseShortPrimitive(DeserializationContext ctxt, JsonPars
return ((Short) ctxt.handleUnexpectedToken(ctxt.constructType(Short.TYPE), p)).shortValue();
}

@Deprecated // since 2.12, use overloaded variant
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt) throws IOException {
return _parseIntPrimitive(ctxt, p);
}

protected final int _parseIntPrimitive(DeserializationContext ctxt, JsonParser p)
throws IOException
{
@@ -603,12 +598,6 @@ protected final int _parseIntPrimitive(DeserializationContext ctxt, String text)
}
}

@Deprecated // since 2.12, use overloaded variant
protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException {
return _parseLongPrimitive(ctxt, p);
}

protected final long _parseLongPrimitive(DeserializationContext ctxt, JsonParser p)
throws IOException
{
@@ -669,12 +658,6 @@ protected final long _parseLongPrimitive(DeserializationContext ctxt, String tex
}
}

@Deprecated // since 2.12, use overloaded variant
protected final float _parseFloatPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException {
return _parseFloatPrimitive(ctxt, p);
}

protected final float _parseFloatPrimitive(DeserializationContext ctxt, JsonParser p)
throws IOException
{
@@ -743,12 +726,6 @@ protected final float _parseFloatPrimitive(DeserializationContext ctxt, String t
return _nonNullNumber(v).floatValue();
}

@Deprecated // since 2.12, use overloaded variant
protected final double _parseDoublePrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException {
return _parseDoublePrimitive(ctxt, p);
}

protected final double _parseDoublePrimitive(DeserializationContext ctxt, JsonParser p)
throws IOException
{
@@ -954,10 +931,6 @@ protected boolean _hasTextualNull(String value) {
return "null".equals(value);
}

protected boolean _isEmptyOrTextualNull(String value) {
return value.isEmpty() || "null".equals(value);
}

protected final boolean _isNegInf(String text) {
return "-Infinity".equals(text) || "-INF".equals(text);
}
@@ -1077,6 +1050,25 @@ protected CoercionAction _checkCoercionActionFail(DeserializationContext ctxt,
return act;
}

/**
* Method called when otherwise unrecognized String value is encountered for
* a non-primitive type: should see if it is String value {@code "null"}, and if so,
* whether it is acceptable according to configuration or not
*
* @since 2.12
*/
protected boolean _checkTextualNull(DeserializationContext ctxt, String text)
throws JsonMappingException
{
if (_hasTextualNull(text)) {
if (!ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)) {
_reportFailedNullCoerce(ctxt, true, MapperFeature.ALLOW_COERCION_OF_SCALARS, "String \"null\"");
}
return true;
}
return false;
}

/*
/**********************************************************************
/* Helper methods for sub-classes, coercions, older (pre-2.12), non-deprecated
@@ -1107,29 +1099,13 @@ protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) thro
}

/**
* Method called when JSON String with value "null" is encountered.
* Method called to verify that {@code null} token from input is acceptable
* for primitive (unboxed) target type. It should NOT be called if {@code null}
* was received by other means (coerced due to configuration, or even from
* optionally acceptable String {@code "null"} token).
*
* @since 2.9
*/
protected Object _coerceTextualNull(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, "String \"null\"");
return null;
}

// @since 2.9
protected final void _verifyNullForPrimitive(DeserializationContext ctxt) throws JsonMappingException
{
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) {
@@ -1139,8 +1115,14 @@ protected final void _verifyNullForPrimitive(DeserializationContext ctxt) throws
}
}

// NOTE: only for primitive Scalars
// @since 2.9
/**
* Method called to verify that text value {@code "null"} from input is acceptable
* for primitive (unboxed) target type. It should not be called if actual
* {@code null} token was received, or if null is a result of coercion from
* Some other input type.
*
* @since 2.9
*/
protected final void _verifyNullForPrimitiveCoercion(DeserializationContext ctxt, String str) throws JsonMappingException
{
Enum<?> feat;
Original file line number Diff line number Diff line change
@@ -40,8 +40,7 @@ public OptionalDouble deserialize(JsonParser p, DeserializationContext ctxt) thr
return (OptionalDouble) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
_coerceTextualNull(ctxt, false);
if (_checkTextualNull(ctxt, text)) {
return _empty;
}
return OptionalDouble.of(_parseDoublePrimitive(ctxt, text));
Original file line number Diff line number Diff line change
@@ -40,9 +40,8 @@ public OptionalInt deserialize(JsonParser p, DeserializationContext ctxt) throws
return (OptionalInt) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
_coerceTextualNull(ctxt, false);
return _empty;
if (_checkTextualNull(ctxt, text)) {
return (OptionalInt) getNullValue(ctxt);
}
return OptionalInt.of(_parseIntPrimitive(ctxt, text));
case JsonTokenId.ID_NUMBER_FLOAT:
Original file line number Diff line number Diff line change
@@ -41,9 +41,8 @@ public OptionalLong deserialize(JsonParser p, DeserializationContext ctxt) throw
return (OptionalLong) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
_coerceTextualNull(ctxt, false);
return _empty;
if (_checkTextualNull(ctxt, text)) {
return (OptionalLong) getNullValue(ctxt);
}
return OptionalLong.of(_parseLongPrimitive(ctxt, text));
case JsonTokenId.ID_NUMBER_FLOAT:

0 comments on commit 32a38ee

Please sign in to comment.