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 7e21f3d + 1e99a57 commit dd40ecb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,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:
Expand Down Expand Up @@ -377,8 +377,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:
Expand Down Expand Up @@ -438,7 +438,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:
Expand Down Expand Up @@ -532,8 +535,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);
}
Expand Down Expand Up @@ -599,8 +602,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:
Expand Down Expand Up @@ -674,8 +677,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();
Expand Down Expand Up @@ -763,8 +766,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,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,
Expand All @@ -404,6 +395,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);
}
Expand Down Expand Up @@ -1106,20 +1106,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.
*
Expand Down Expand Up @@ -1218,6 +1204,15 @@ protected String _coercedTypeDesc() {

// Removed from 3.0

@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
Expand Down

0 comments on commit dd40ecb

Please sign in to comment.