Skip to content

Consider DefaultTyping configuration in Jackson Serializers#3309

Draft
mp911de wants to merge 3 commits intomainfrom
issue/3306
Draft

Consider DefaultTyping configuration in Jackson Serializers#3309
mp911de wants to merge 3 commits intomainfrom
issue/3306

Conversation

@mp911de
Copy link
Member

@mp911de mp911de commented Feb 10, 2026

We're exploring whether it makes sense to accept a DefaultTyping config option for Jackson serializer configuration.

Likely, accepting DefaultTyping causes several downstream effects that we actually do not like (e.g. removing typehints for final types such as records likely breaking their support).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 10, 2026
@mp911de mp911de marked this pull request as draft February 10, 2026 14:46
@mp911de mp911de added the status: pending-design-work Needs design work before any code can be developed label Mar 2, 2026
mp911de added 2 commits March 12, 2026 19:08
We're exploring whether it makes sense to accept a `DefaultTyping` config option for Jackson serializer configuration.
This introduces a `Predicate<JavaType>` that can be specified on the
`GenericJackson2JsonRedisSerializer` to give the fine-grained control
over what types should include type hint info during serialization.

Fixes #3306
private @Nullable Boolean defaultTypingEnabled;

private @Nullable DefaultTyping defaultTyping;
private @Nullable Predicate<JavaType> defaultTyping;
Copy link
Member Author

@mp911de mp911de Mar 13, 2026

Choose a reason for hiding this comment

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

That's a direction I ended up with, too. A single Predicate is likely not going to be sufficient. The code to determine whether to apply default typing contains opinions of ours. We would want to achieve an approach that allows folks to override our opinion or append theirs (that is, take some of our opinions but do something different for a type that we handle or apply/avoid typing for types we don't handle).

What if we introduced a DefaultTypingPredicate interface returning something like YES, NO, I_DONT_HAVE_AN_OPINION allowing functional composition?

DefaultTyping.defaults()
   .and(DefaultTyping.apply((Class<?> it) -> it.isEnum())
   .and(DefaultTyping.skip((Class<?> it) -> it.isPrimitive())
   .and((Class<?> it) -> it.isRecord() ? DefaultTyping.apply() : DefaultTyping.continue());

or

DefaultTyping.defaults()
   .and((Class<?> it) -> it.isRecord() ? DefaultTyping.include() : DefaultTyping.passThrough())
   .and(DefaultTyping.include((Class<?> it) -> it.isEnum()))
//    .andInclude ((Class<?> it) -> it.isEnum())
   .and(DefaultTyping.exclude((Class<?> it) -> it.isPrimitive()))
//   .andExclude((Class<?> it) -> it.isPrimitive())
   .and(MyApplicationSpecificTyping.INSTANCE);

We'd need an idea on naming, though.

@onobc onobc removed the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: pending-design-work Needs design work before any code can be developed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RedisCache with GenericJacksonJsonRedisSerializer breaks when using enums

3 participants