diff --git a/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JacksonJrsTreeCodec.java b/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JacksonJrsTreeCodec.java index 6e14afe5..fef999da 100644 --- a/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JacksonJrsTreeCodec.java +++ b/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JacksonJrsTreeCodec.java @@ -13,12 +13,12 @@ */ public class JacksonJrsTreeCodec extends TreeCodec { - public static JrsMissing MISSING = JrsMissing.instance; protected final ObjectCodec _objectCodec; // @since 2.17 protected boolean _failOnDuplicateKeys; - + protected boolean _useBigDouble; + public JacksonJrsTreeCodec() { this(null); } @@ -28,10 +28,11 @@ public JacksonJrsTreeCodec(ObjectCodec codec) { } // @since 2.17 - public void setFailOnDuplicateKeys(boolean state) { - _failOnDuplicateKeys = state; + public void setFailOnDuplicateKeys(boolean failOnDuplicateKeys,boolean useBigDouble) { + _failOnDuplicateKeys = failOnDuplicateKeys; + _useBigDouble = useBigDouble; } - + @SuppressWarnings("unchecked") @Override public T readTree(JsonParser p) throws IOException { @@ -50,7 +51,16 @@ private JrsValue nodeFrom(JsonParser p) throws IOException return JrsBoolean.FALSE; case JsonTokenId.ID_NUMBER_INT: case JsonTokenId.ID_NUMBER_FLOAT: - return new JrsNumber(p.getNumberValue()); + if (_useBigDouble) { + JsonParser.NumberType n = p.getNumberType(); + if (n == JsonParser.NumberType.FLOAT) { + return new JrsNumber(p.getFloatValue()); + } + if (n == JsonParser.NumberType.DOUBLE) { + return new JrsNumber(p.getDoubleValue()); + } + } + return new JrsNumber(p.getDecimalValue()); case JsonTokenId.ID_STRING: return new JrsString(p.getText()); case JsonTokenId.ID_START_ARRAY: { diff --git a/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JrSimpleTreeExtension.java b/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JrSimpleTreeExtension.java index d3588fcc..bbee7373 100644 --- a/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JrSimpleTreeExtension.java +++ b/jr-stree/src/main/java/com/fasterxml/jackson/jr/stree/JrSimpleTreeExtension.java @@ -27,7 +27,7 @@ public JrSimpleTreeExtension(JacksonJrsTreeCodec tc) { @Override protected void register(ExtensionContext ctxt) { - _codec.setFailOnDuplicateKeys(ctxt.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)); + _codec.setFailOnDuplicateKeys(ctxt.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS), ctxt.isEnabled(JSON.Feature.USE_BIG_DECIMAL_FOR_FLOATS)); ctxt.setTreeCodec(_codec); } } diff --git a/jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/failing/ReadAsBigDecimal90Test.java b/jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/ReadAsBigDecimal90Test.java similarity index 85% rename from jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/failing/ReadAsBigDecimal90Test.java rename to jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/ReadAsBigDecimal90Test.java index e1e84758..a5ad1bae 100644 --- a/jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/failing/ReadAsBigDecimal90Test.java +++ b/jr-stree/src/test/java/com/fasterxml/jackson/jr/stree/ReadAsBigDecimal90Test.java @@ -1,11 +1,9 @@ -package com.fasterxml.jackson.jr.stree.failing; - -import java.math.BigDecimal; +package com.fasterxml.jackson.jr.stree; import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.jr.ob.JSON; -import com.fasterxml.jackson.jr.ob.*; -import com.fasterxml.jackson.jr.stree.*; +import java.math.BigDecimal; public class ReadAsBigDecimal90Test extends JacksonJrTreeTestBase {