Skip to content

test case for serializing custom numbers with config overrides #5198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2025

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Jun 18, 2025

  • relates to a broken test in jackson-module-scala - Create NumberSerializerTest.scala jackson-module-scala#748 - that 748 test basically works with Jackson 2 (and is merged in jackson-module-scala 2.x branch)
  • Scala has scala.math.BigDecimal which is a wrapper on java.math.BigDecimal but we don't want test cases in jackson-databind that bring in outside dependencies. The MyBigDecimal class in this PR is enough to trigger the issue
  • of the 2 unit tests, the BigDecimal one already works but the MyBigDecimal one fails
  • I did a little debugging and the code in BasicSerializerFactory.java to check the config overrides has changed quite a bit in Jackson 3 and the changes cause this test case to fail

@pjfanning pjfanning added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Jun 18, 2025
@@ -161,6 +161,9 @@ public ValueSerializer<Object> createSerializer(SerializationContext ctxt, JavaT
beanDescRef = ctxt.lazyIntrospectBeanDescription(type);
}
}
if (formatOverrides == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like patching a bug further upstream? I'll have to think about this bit more -- after vacation (going on vacation today), so it'll be some time until I get back, but will go through it then.

@@ -323,7 +323,9 @@ protected final ValueSerializer<?> findSerializerByPrimaryType(SerializationCont
return null;
default:
}
return NumberSerializer.instance;
@SuppressWarnings("unchecked")
Class<? extends Number> numberType = (Class<? extends Number>) rawType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably work without this part too, but seems more correct to specify handled type as real type, not Number.

@cowtowncoder
Copy link
Member

@pjfanning I changed the solution slightly, will now merge. While it seems like override target ideally should be BigDecimal, this is the way 2.x works & NumberSerializer would otherwise need to sort of enumerate "proper" handled types available (to distinguish JDK types like BigDecimal, BigInteger from custom subtypes) and... things would get bit complicated.

@cowtowncoder cowtowncoder merged commit c5bc67a into FasterXML:3.x Jul 12, 2025
6 checks passed
@pjfanning pjfanning deleted the custom-num-ser branch July 12, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants