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 c1f9377 + d6510b8 commit e1253d6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ public final LogicalType logicalType() {
@Override
public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
CoercionAction act;
switch (p.currentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
switch (p.getNumberType()) {
Expand All @@ -938,15 +939,19 @@ public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws
}
break;
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "java.math.BigInteger");
act = _checkFloatToIntCoercion(ctxt, p, _valueClass);
if (act == CoercionAction.AsNull) {
return (BigInteger) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (BigInteger) getEmptyValue(ctxt);
}
return p.getDecimalValue().toBigInteger();
case JsonTokenId.ID_START_ARRAY:
return _deserializeFromArray(p, ctxt);
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText();
CoercionAction act = _checkFromStringCoercion(ctxt, text);
act = _checkFromStringCoercion(ctxt, text);
if (act == CoercionAction.AsNull) {
return (BigInteger) getNullValue(ctxt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,19 +1078,11 @@ protected CoercionAction _checkCoercionActionFail(DeserializationContext ctxt,
}

/*
/****************************************************
/* Helper methods for sub-classes, coercions, older (pre-2.12)
/****************************************************
/**********************************************************************
/* Helper methods for sub-classes, coercions, older (pre-2.12), non-deprecated
/**********************************************************************
*/

protected void _failDoubleToIntCoercion(JsonParser p, DeserializationContext ctxt,
String type) throws IOException
{
ctxt.reportInputMismatch(handledType(),
"Cannot coerce a floating-point value ('%s') into %s (enable `DeserializationFeature.ACCEPT_FLOAT_AS_INT` to allow)",
p.getValueAsString(), type);
}

/**
* Helper method called in case where an integral number is encountered, but
* config settings suggest that a coercion may be needed to "upgrade"
Expand All @@ -1099,6 +1091,8 @@ protected void _failDoubleToIntCoercion(JsonParser p, DeserializationContext ctx
*
* @see DeserializationFeature#USE_BIG_INTEGER_FOR_INTS
* @see DeserializationFeature#USE_LONG_FOR_INTS
*
* @since 2.6
*/
protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) throws IOException
{
Expand All @@ -1109,9 +1103,15 @@ protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) thro
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getBigIntegerValue(); // should be optimal, whatever it is
return p.getNumberValue(); // should be optimal, whatever it is
}

/*
/**********************************************************************
/* Helper methods for sub-classes, coercions, older (pre-2.12), deprecated
/**********************************************************************
*/

/**
* Method to call when JSON `null` token is encountered. Note: only called when
* this deserializer encounters it but NOT when reached via property
Expand Down Expand Up @@ -1179,8 +1179,7 @@ protected final void _verifyNullForPrimitiveCoercion(DeserializationContext ctxt
_reportFailedNullCoerce(ctxt, enable, feat, strDesc);
}

// NOTE: for non-primitive Scalars
// @since 2.9
@Deprecated // since 2.12
protected final void _verifyNullForScalarCoercion(DeserializationContext ctxt, String str) throws JsonMappingException
{
if (!ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,30 @@ public OptionalInt deserialize(JsonParser p, DeserializationContext ctxt) throws
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return OptionalInt.of(p.getIntValue());
}
CoercionAction act;
switch (p.currentTokenId()) {
case JsonTokenId.ID_STRING:
{
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));
String text = p.getText();
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));
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "int");
act = _checkFloatToIntCoercion(ctxt, p, _valueClass);
if (act == CoercionAction.AsNull) {
return (OptionalInt) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (OptionalInt) getEmptyValue(ctxt);
}
return OptionalInt.of(p.getValueAsInt());
case JsonTokenId.ID_NULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ public OptionalLong deserialize(JsonParser p, DeserializationContext ctxt) throw
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return OptionalLong.of(p.getLongValue());
}
CoercionAction act;
switch (p.currentTokenId()) {
case JsonTokenId.ID_STRING:
{
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));
String text = p.getText();
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));
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "long");
act = _checkFloatToIntCoercion(ctxt, p, _valueClass);
if (act == CoercionAction.AsNull) {
return (OptionalLong) getNullValue(ctxt);
}
if (act == CoercionAction.AsEmpty) {
return (OptionalLong) getEmptyValue(ctxt);
}
return OptionalLong.of(p.getValueAsLong());
case JsonTokenId.ID_NULL:
Expand Down

0 comments on commit e1253d6

Please sign in to comment.