use of com.fasterxml.jackson.core.exc.InputCoercionException in project curiostack by curioswitch.
the class ParseSupport method parseUInt64.
/**
* Parsers a uint64 value out of the input.
*/
public static long parseUInt64(JsonParser parser) throws IOException {
// cover the vast majority of cases.
try {
long result = parseLong(parser);
if (result >= 0) {
// Only need to check the uint32 range if the parsed long is negative.
return result;
}
} catch (JsonParseException | InputCoercionException | NumberFormatException e) {
// Fall through.
}
final BigInteger value;
try {
BigDecimal decimal = new BigDecimal(parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
value = decimal.toBigIntegerExact();
} catch (ArithmeticException | NumberFormatException e) {
throw new InvalidProtocolBufferException("Not an uint64 value: " + parser.getText());
}
if (value.compareTo(BigInteger.ZERO) < 0 || value.compareTo(MAX_UINT64) > 0) {
throw new InvalidProtocolBufferException("Out of range uint64 value: " + parser.getText());
}
return value.longValue();
}
Aggregations