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 7, 2020
2 parents 14a1766 + 1452606 commit e70f471
Showing 1 changed file with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ protected final Boolean _parseBoolean(JsonParser p, DeserializationContext ctxt)
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
final String text = p.getText();

String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (Boolean) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (Boolean) getEmptyValue(ctxt);
}
text = text.trim();
// [databind#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return Boolean.TRUE;
Expand Down Expand Up @@ -303,14 +303,15 @@ protected Byte _parseByte(JsonParser p, DeserializationContext ctxt) throws IOEx
{
JsonToken t = p.currentToken();
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
final String text = p.getText();
String text = p.getText();
CoercionAction 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, _primitive);
}
Expand Down Expand Up @@ -376,14 +377,15 @@ protected Short _parseShort(JsonParser p, DeserializationContext ctxt) throws IO
return p.getShortValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
final String text = p.getText();
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, _primitive);
}
Expand Down Expand Up @@ -445,14 +447,15 @@ public Character deserialize(JsonParser p, DeserializationContext ctxt)
break;
case JsonTokenId.ID_STRING: // this is the usual type

final String text = p.getText();
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (Character) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (Character) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Character) _coerceTextualNull(ctxt, _primitive);
}
Expand Down Expand Up @@ -518,14 +521,15 @@ protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt)
}
return Integer.valueOf(p.getValueAsInt());
case JsonTokenId.ID_STRING: // let's do implicit re-parse
final String text = p.getText();
String text = p.getText();
CoercionAction 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, _primitive);
}
Expand Down Expand Up @@ -590,14 +594,15 @@ protected final Long _parseLong(JsonParser p, DeserializationContext ctxt) throw
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
final String text = p.getText();
String text = p.getText();
CoercionAction 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, _primitive);
}
Expand Down Expand Up @@ -645,14 +650,15 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt)
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
final String text = p.getText();
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (Float) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (Float) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Float) _coerceTextualNull(ctxt, _primitive);
}
Expand Down Expand Up @@ -722,14 +728,15 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t
return p.getDoubleValue();
}
if (t == JsonToken.VALUE_STRING) {
final String text = p.getText();
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (Double) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (Double) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
return (Double) _coerceTextualNull(ctxt, _primitive);
}
Expand Down Expand Up @@ -813,14 +820,18 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
return p.getNumberValue();

case JsonTokenId.ID_STRING:
/* Textual values are more difficult... not parsing itself, but figuring
* out 'minimal' type to use
*/
String text = p.getText().trim();
if ((text.length() == 0)) {
// note: no need to call `coerce` as this is never primitive
// Textual values are more difficult... not parsing itself, but figuring
// out 'minimal' type to use

String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
// note: no need to call `coerce` as this is never primitive
return getNullValue(ctxt);
Expand All @@ -834,7 +845,6 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
if (_isNaN(text)) {
return Double.NaN;
}
_verifyStringForScalarCoercion(ctxt, text);
try {
if (!_isIntNumber(text)) {
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
Expand Down Expand Up @@ -887,8 +897,7 @@ public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,

/*
/**********************************************************
/* And then bit more complicated (but non-structured) number
/* types
/* And then bit more complicated (but non-structured) number types
/**********************************************************
*/

Expand Down Expand Up @@ -935,13 +944,19 @@ public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws
case JsonTokenId.ID_START_ARRAY:
return _deserializeFromArray(p, ctxt);
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
// note: no need to call `coerce` as this is never primitive
if (_isEmptyOrTextualNull(text)) {
_verifyNullForScalarCoercion(ctxt, text);
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (BigInteger) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (BigInteger) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
// note: no need to call `coerce` as this is never primitive
return (BigInteger) getNullValue(ctxt);
}
_verifyStringForScalarCoercion(ctxt, text);
try {
return new BigInteger(text);
} catch (IllegalArgumentException iae) { }
Expand Down Expand Up @@ -980,13 +995,19 @@ public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt)
case JsonTokenId.ID_NUMBER_FLOAT:
return p.getDecimalValue();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
// note: no need to call `coerce` as this is never primitive
if (_isEmptyOrTextualNull(text)) {
_verifyNullForScalarCoercion(ctxt, text);
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (BigDecimal) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (BigDecimal) getEmptyValue(ctxt);
}
text = text.trim();
if (_hasTextualNull(text)) {
// note: no need to call `coerce` as this is never primitive
return (BigDecimal) getNullValue(ctxt);
}
_verifyStringForScalarCoercion(ctxt, text);
try {
return new BigDecimal(text);
} catch (IllegalArgumentException iae) { }
Expand Down

0 comments on commit e70f471

Please sign in to comment.