|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.BaseTest; |
| 4 | +import com.fasterxml.jackson.core.JsonFactory; |
| 5 | +import com.fasterxml.jackson.core.JsonGenerator; |
| 6 | +import com.fasterxml.jackson.core.JsonParser; |
| 7 | + |
| 8 | +import java.io.ByteArrayOutputStream; |
| 9 | +import java.io.StringWriter; |
| 10 | + |
| 11 | +public class ParserPrecisionLoss733Test extends BaseTest { |
| 12 | + final JsonFactory JSON_F = newStreamFactory(); |
| 13 | + |
| 14 | + /** |
| 15 | + * Attempt to pass a BigDecimal value through without losing precision, |
| 16 | + * e.g. for pretty printing a file. |
| 17 | + */ |
| 18 | + public void testCopyCurrentEventBigDecimal() throws Exception { |
| 19 | + String input = "1e999"; |
| 20 | + JsonParser parser = JSON_F.createParser(input); |
| 21 | + parser.nextToken(); |
| 22 | + StringWriter stringWriter = new StringWriter(); |
| 23 | + JsonGenerator generator = JSON_F.createGenerator(stringWriter); |
| 24 | + generator.copyCurrentEvent(parser); |
| 25 | + parser.close(); |
| 26 | + generator.close(); |
| 27 | + String actual = stringWriter.toString(); |
| 28 | + assertEquals(input, actual); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Same as {@link #testCopyCurrentEventBigDecimal()} using copyCurrentStructure instead. |
| 33 | + */ |
| 34 | + public void testCopyCurrentStructureBigDecimal() throws Exception { |
| 35 | + String input = "[1e999]"; |
| 36 | + JsonParser parser = JSON_F.createParser(input); |
| 37 | + parser.nextToken(); |
| 38 | + StringWriter stringWriter = new StringWriter(); |
| 39 | + JsonGenerator generator = JSON_F.createGenerator(stringWriter); |
| 40 | + generator.copyCurrentStructure(parser); |
| 41 | + parser.close(); |
| 42 | + generator.close(); |
| 43 | + String actual = stringWriter.toString(); |
| 44 | + assertEquals(input, actual); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments