Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 13, 2020
1 parent 26414f5 commit d6510b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,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 @@ -969,15 +970,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 getNullValue(ctxt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,40 @@ 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
/**********************************************************************
*/

/**
* Helper method called in case where an integral number is encountered, but
* config settings suggest that a coercion may be needed to "upgrade"
* {@link java.lang.Number} into "bigger" type like {@link java.lang.Long} or
* {@link java.math.BigInteger}
*
* @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
{
int feats = ctxt.getDeserializationFeatures();
if (DeserializationFeature.USE_BIG_INTEGER_FOR_INTS.enabledIn(feats)) {
return p.getBigIntegerValue();
}
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getNumberValue(); // should be optimal, whatever it is
}

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

/**
* @deprecated Since 2.12 use {@link #_checkFromStringCoercion} instead
*/
Expand Down Expand Up @@ -1225,6 +1254,7 @@ protected Object _coerceEmptyString(DeserializationContext ctxt, boolean isPrimi
return null;
}

@Deprecated // since 2.12
protected void _failDoubleToIntCoercion(JsonParser p, DeserializationContext ctxt,
String type) throws IOException
{
Expand All @@ -1233,29 +1263,6 @@ protected void _failDoubleToIntCoercion(JsonParser p, DeserializationContext ctx
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"
* {@link java.lang.Number} into "bigger" type like {@link java.lang.Long} or
* {@link java.math.BigInteger}
*
* @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
{
int feats = ctxt.getDeserializationFeatures();
if (DeserializationFeature.USE_BIG_INTEGER_FOR_INTS.enabledIn(feats)) {
return p.getBigIntegerValue();
}
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getBigIntegerValue(); // 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
Expand Down Expand Up @@ -1323,8 +1330,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

0 comments on commit d6510b8

Please sign in to comment.