Skip to content

Commit

Permalink
support StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER (FasterXML#3685)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Dec 3, 2022
1 parent bca1131 commit 3f29ef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,14 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
try {
if (!_isIntNumber(text)) {
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return NumberInput.parseBigDecimal(text);
return NumberInput.parseBigDecimal(
text, p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
}
return Double.valueOf(
NumberInput.parseDouble(text, p.isEnabled(StreamReadFeature.USE_FAST_DOUBLE_PARSER)));
}
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) {
return NumberInput.parseBigInteger(text);
return NumberInput.parseBigInteger(text, p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
}
long value = NumberInput.parseLong(text);
if (!ctxt.isEnabled(DeserializationFeature.USE_LONG_FOR_INTS)) {
Expand Down Expand Up @@ -961,7 +962,7 @@ public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws
return getNullValue(ctxt);
}
try {
return NumberInput.parseBigInteger(text);
return NumberInput.parseBigInteger(text, p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
} catch (IllegalArgumentException iae) { }
return (BigInteger) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid representation");
Expand Down Expand Up @@ -1030,7 +1031,7 @@ public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt)
return getNullValue(ctxt);
}
try {
return NumberInput.parseBigDecimal(text);
return NumberInput.parseBigDecimal(text, p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
} catch (IllegalArgumentException iae) { }
return (BigDecimal) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid representation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,13 @@ private void testObjectReaderWithFastDoubleParser(final boolean useParserFeature
if (useParserFeature) {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.USE_FAST_DOUBLE_PARSER);
factory.enable(JsonParser.Feature.USE_FAST_BIG_NUMBER_PARSER);
mapper = JsonMapper.builder(factory).build();
} else {
mapper = JsonMapper.builder().enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER).build();
mapper = JsonMapper.builder()
.enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER)
.enable(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER)
.build();
}

final MappingIterator<Map<String, Double>> iterator = mapper.reader().forType(new TypeReference<Map<String, Double>>(){}).readValues(JSON);
Expand All @@ -399,9 +403,13 @@ private void testObjectReaderWithFastFloatParser(final boolean useParserFeature)
if (useParserFeature) {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.USE_FAST_DOUBLE_PARSER);
factory.enable(JsonParser.Feature.USE_FAST_BIG_NUMBER_PARSER);
mapper = JsonMapper.builder(factory).build();
} else {
mapper = JsonMapper.builder().enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER).build();
mapper = JsonMapper.builder()
.enable(StreamReadFeature.USE_FAST_DOUBLE_PARSER)
.enable(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER)
.build();
}
final MappingIterator<Map<String, Float>> iterator = mapper.reader().forType(new TypeReference<Map<String, Float>>(){}).readValues(JSON);

Expand Down

0 comments on commit 3f29ef4

Please sign in to comment.