From 3f29ef4ff81c635312a2e04b838280633f370787 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 3 Dec 2022 18:21:18 +0100 Subject: [PATCH] support StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER (#3685) --- .../databind/deser/std/NumberDeserializers.java | 9 +++++---- .../jackson/databind/seq/ReadValuesTest.java | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java index 15b6d9f5e2..8ab9e9bb48 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/NumberDeserializers.java @@ -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)) { @@ -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"); @@ -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"); diff --git a/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java b/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java index b3ee8136b0..23e8761c95 100644 --- a/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java @@ -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> iterator = mapper.reader().forType(new TypeReference>(){}).readValues(JSON); @@ -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> iterator = mapper.reader().forType(new TypeReference>(){}).readValues(JSON);