-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38a61e0
commit b4dea3c
Showing
2 changed files
with
42 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
src/test/java/com/fasterxml/jackson/failing/BigDecimalPlain2230Test.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,37 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import com.fasterxml.jackson.core.StreamWriteFeature; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class BigDecimalPlain2230Test extends BaseMapTest | ||
{ | ||
static class BigDecimalAsString { | ||
@JsonFormat(shape=JsonFormat.Shape.STRING) | ||
public BigDecimal value; | ||
|
||
public BigDecimalAsString() { this(BigDecimal.valueOf(0.25)); } | ||
public BigDecimalAsString(BigDecimal v) { value = v; } | ||
} | ||
|
||
private final ObjectMapper MAPPER = objectMapper(); | ||
|
||
public void testBigIntegerAsPlainTest() throws Exception | ||
{ | ||
final String NORM_VALUE = "0.0000000005"; | ||
final BigDecimal BD_VALUE = new BigDecimal(NORM_VALUE); | ||
final BigDecimalAsString INPUT = new BigDecimalAsString(BD_VALUE); | ||
// by default, use the default `toString()` | ||
assertEquals("{\"value\":\""+BD_VALUE.toString()+"\"", MAPPER.writeValueAsString(INPUT)); | ||
|
||
// but can force to "plain" notation | ||
final ObjectMapper m = jsonMapperBuilder() | ||
.enable(StreamWriteFeature.WRITE_BIGDECIMAL_AS_PLAIN) | ||
.build(); | ||
assertEquals("{\"value\":\""+NORM_VALUE+"\"", m.writeValueAsString(INPUT)); | ||
} | ||
} |