|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.math.BigDecimal; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +import com.fasterxml.jackson.annotation.JsonFormat; |
| 7 | +import com.fasterxml.jackson.databind.*; |
| 8 | + |
| 9 | +public class BigDecimalAsString2519Test extends BaseMapTest |
| 10 | +{ |
| 11 | + static class Bean2519Typed { |
| 12 | + public List<BigDecimal> values = new ArrayList<>(); |
| 13 | + } |
| 14 | + |
| 15 | + static class Bean2519Untyped { |
| 16 | + public Collection<BigDecimal> values = new HashSet<>(); |
| 17 | + } |
| 18 | + |
| 19 | + public void testBigDecimalAsString2519Typed() throws Exception |
| 20 | + { |
| 21 | + Bean2519Typed foo = new Bean2519Typed(); |
| 22 | + foo.values.add(new BigDecimal("2.34")); |
| 23 | + final ObjectMapper mapper = new ObjectMapper(); |
| 24 | + mapper.configOverride(BigDecimal.class) |
| 25 | + .setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)); |
| 26 | + String json = mapper.writeValueAsString(foo); |
| 27 | + assertEquals(aposToQuotes("{'values':['2.34']}"), json); |
| 28 | + } |
| 29 | + |
| 30 | + public void testBigDecimalAsString2519Untyped() throws Exception |
| 31 | + { |
| 32 | + Bean2519Untyped foo = new Bean2519Untyped(); |
| 33 | + foo.values.add(new BigDecimal("2.34")); |
| 34 | + final ObjectMapper mapper = new ObjectMapper(); |
| 35 | + mapper.configOverride(BigDecimal.class) |
| 36 | + .setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)); |
| 37 | + String json = mapper.writeValueAsString(foo); |
| 38 | + assertEquals(aposToQuotes("{'values':['2.34']}"), json); |
| 39 | + } |
| 40 | +} |
0 commit comments