Skip to content

Commit ce2b69a

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 3e29398 + d9ac438 commit ce2b69a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/java/tools/jackson/databind/ser/jdk/NumberSerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public void serialize(BigDecimal value, JsonGenerator gen, SerializationContext
117117
}
118118
}
119119

120+
static class MyBigDecimal extends BigDecimal {
121+
public MyBigDecimal(String value) {
122+
super(value);
123+
}
124+
}
125+
120126
/*
121127
/**********************************************************
122128
/* Test methods
@@ -225,6 +231,24 @@ public void testCustomSerializationBigDecimalAsNumber() throws Exception {
225231
assertEquals(a2q("{'value':2.0}"), mapper.writeValueAsString(new BigDecimalHolder("2")));
226232
}
227233

234+
@Test
235+
public void testConfigOverrideJdkNumber() throws Exception {
236+
ObjectMapper mapper = jsonMapperBuilder().withConfigOverride(BigDecimal.class,
237+
c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
238+
.build();
239+
String value = mapper.writeValueAsString(new BigDecimal("123.456"));
240+
assertEquals(a2q("'123.456'"), value);
241+
}
242+
243+
@Test
244+
public void testConfigOverrideNonJdkNumber() throws Exception {
245+
ObjectMapper mapper = jsonMapperBuilder().withConfigOverride(MyBigDecimal.class,
246+
c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
247+
.build();
248+
String value = mapper.writeValueAsString(new MyBigDecimal("123.456"));
249+
assertEquals(a2q("'123.456'"), value);
250+
}
251+
228252
// default locale is en_US
229253
static DecimalFormat createDecimalFormatForDefaultLocale(final String pattern) {
230254
return new DecimalFormat(pattern, new DecimalFormatSymbols(Locale.ENGLISH));

0 commit comments

Comments
 (0)