diff --git a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java index fbc56a8d3b..fa593bc2bd 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java @@ -2491,13 +2491,13 @@ public void copyCurrentEvent(JsonParser p) throws IOException } case ID_NUMBER_FLOAT: { - NumberType n = p.getNumberType(); - if (n == NumberType.BIG_DECIMAL) { - writeNumber(p.getDecimalValue()); - } else if (n == NumberType.FLOAT) { - writeNumber(p.getFloatValue()); + Number n = p.getNumberValueExact(); + if (n instanceof Float) { + writeNumber((Float) n); + } else if (n instanceof BigDecimal) { + writeNumber((BigDecimal) n); } else { - writeNumber(p.getDoubleValue()); + writeNumber(n.doubleValue()); } break; } @@ -2636,13 +2636,13 @@ protected void _copyCurrentContents(JsonParser p) throws IOException } case ID_NUMBER_FLOAT: { - NumberType n = p.getNumberType(); - if (n == NumberType.BIG_DECIMAL) { - writeNumber(p.getDecimalValue()); - } else if (n == NumberType.FLOAT) { - writeNumber(p.getFloatValue()); + Number n = p.getNumberValueExact(); + if (n instanceof Float) { + writeNumber((Float) n); + } else if (n instanceof BigDecimal) { + writeNumber((BigDecimal) n); } else { - writeNumber(p.getDoubleValue()); + writeNumber(n.doubleValue()); } break; } diff --git a/src/test/java/com/fasterxml/jackson/failing/ParserPrecisionLoss730Test.java b/src/test/java/com/fasterxml/jackson/failing/ParserPrecisionLoss730Test.java index aad7abc4d3..9b68865b5c 100644 --- a/src/test/java/com/fasterxml/jackson/failing/ParserPrecisionLoss730Test.java +++ b/src/test/java/com/fasterxml/jackson/failing/ParserPrecisionLoss730Test.java @@ -18,7 +18,7 @@ public class ParserPrecisionLoss730Test extends BaseTest * e.g. for pretty printing a file. */ public void testCopyCurrentEventBigDecimal() throws Exception { - String input = "1e999"; + String input = "1E+999"; StringWriter stringWriter = new StringWriter(); try (JsonParser parser = JSON_F.createParser(input)) { @@ -43,6 +43,6 @@ public void testCopyCurrentStructureBigDecimal() throws Exception { generator.copyCurrentStructure(parser); } } - assertEquals(input, stringWriter.toString()); + assertEquals("[1E+999]", stringWriter.toString()); } }