Skip to content

Commit c5bc67a

Browse files
authored
test case for serializing custom numbers with config overrides (#5198)
1 parent ce2b69a commit c5bc67a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
312312
}
313313

314314
if (type.isTypeOrSubTypeOf(Number.class)) {
315+
final Class<?> rawType = type.getRawClass();
315316
JsonFormat.Value format = _calculateEffectiveFormat(ctxt,
316-
beanDescRef, Number.class, formatOverrides);
317-
317+
beanDescRef, rawType, formatOverrides);
318318
// 21-May-2014, tatu: Couple of alternatives actually
319319
switch (format.getShape()) {
320320
case STRING:
@@ -323,7 +323,9 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
323323
return null;
324324
default:
325325
}
326-
return NumberSerializer.instance;
326+
@SuppressWarnings("unchecked")
327+
Class<? extends Number> numberType = (Class<? extends Number>) rawType;
328+
return new NumberSerializer(numberType);
327329
}
328330
if (type.isTypeOrSubTypeOf(Map.Entry.class)) {
329331
// 18-Oct-2015, tatu: With 2.7, need to dig type info:

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

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

120+
@SuppressWarnings("serial")
120121
static class MyBigDecimal extends BigDecimal {
121122
public MyBigDecimal(String value) {
122123
super(value);

0 commit comments

Comments
 (0)