-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StreamReadCapability.EXACT_FLOATS to signal potential precision l…
…oss for JSON non-doubles. (#733)
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/fasterxml/jackson/failing/ParserPrecisionLoss733Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.core.BaseTest; | ||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.StringWriter; | ||
|
||
public class ParserPrecisionLoss733Test extends BaseTest { | ||
final JsonFactory JSON_F = newStreamFactory(); | ||
|
||
/** | ||
* Attempt to pass a BigDecimal value through without losing precision, | ||
* e.g. for pretty printing a file. | ||
*/ | ||
public void testCopyCurrentEventBigDecimal() throws Exception { | ||
String input = "1e999"; | ||
JsonParser parser = JSON_F.createParser(input); | ||
parser.nextToken(); | ||
StringWriter stringWriter = new StringWriter(); | ||
JsonGenerator generator = JSON_F.createGenerator(stringWriter); | ||
generator.copyCurrentEvent(parser); | ||
parser.close(); | ||
generator.close(); | ||
String actual = stringWriter.toString(); | ||
assertEquals(input, actual); | ||
} | ||
|
||
/** | ||
* Same as {@link #testCopyCurrentEventBigDecimal()} using copyCurrentStructure instead. | ||
*/ | ||
public void testCopyCurrentStructureBigDecimal() throws Exception { | ||
String input = "[1e999]"; | ||
JsonParser parser = JSON_F.createParser(input); | ||
parser.nextToken(); | ||
StringWriter stringWriter = new StringWriter(); | ||
JsonGenerator generator = JSON_F.createGenerator(stringWriter); | ||
generator.copyCurrentStructure(parser); | ||
parser.close(); | ||
generator.close(); | ||
String actual = stringWriter.toString(); | ||
assertEquals(input, actual); | ||
} | ||
|
||
} |