Skip to content

Commit 25823ea

Browse files
committed
add test and change speculative fix
1 parent 1459693 commit 25823ea

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/java/tools/jackson/databind/ser/BasicSerializerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
313313

314314
if (type.isTypeOrSubTypeOf(Number.class)) {
315315
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
316-
beanDescRef, type.getRawClass(), formatOverrides);
316+
beanDescRef, Number.class, formatOverrides);
317317

318318
// 21-May-2014, tatu: Couple of alternatives actually
319319
switch (format.getShape()) {

src/main/java/tools/jackson/databind/ser/BeanSerializerFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public ValueSerializer<Object> createSerializer(SerializationContext ctxt, JavaT
161161
beanDescRef = ctxt.lazyIntrospectBeanDescription(type);
162162
}
163163
}
164+
if (formatOverrides == null) {
165+
formatOverrides = _calculateEffectiveFormat(ctxt, beanDescRef, type.getRawClass(), JsonFormat.Value.empty());
166+
}
164167
// Slight detour: do we have a Converter to consider?
165168
Converter<Object,Object> conv = config.findSerializationConverter(beanDescRef.getClassInfo());
166169
if (conv != null) { // yup, need converter

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,19 @@ public void testCustomSerializationBigDecimalAsNumber() throws Exception {
232232
assertEquals(a2q("{'value':2.0}"), mapper.writeValueAsString(new BigDecimalHolder("2")));
233233
}
234234

235+
@Test
236+
public void testConfigOverrideJdkNumber() throws Exception {
237+
JsonMapper mapper = jsonMapperBuilder().withConfigOverride(BigDecimal.class,
238+
c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
239+
.build();
240+
String value = mapper.writeValueAsString(new BigDecimal("123.456"));
241+
assertEquals(a2q("'123.456'"), value);
242+
}
243+
235244
@Test
236245
public void testConfigOverrideNonJdkNumber() throws Exception {
237246
JsonMapper mapper = jsonMapperBuilder().withConfigOverride(MyBigDecimal.class,
238-
c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
247+
c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
239248
.build();
240249
String value = mapper.writeValueAsString(new MyBigDecimal("123.456"));
241250
assertEquals(a2q("'123.456'"), value);

0 commit comments

Comments
 (0)