FasterXML / FasterXML/jackson-databind

Support disallow list for default typing

Open
#4,182 3 comments 0 reactions 0 assignees View on GitHub
polymorphic-handling
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 6h
Merged PRs (30d)
28

Description

### Is your feature request related to a problem? Please describe.

The idea is that when mapper activateDefaultTyping is enabled that not every class name would be written into the serialized JSON.
For me, this default typing feature is useful when you have a class like `record MyRecord(int id, MyInterface interface)` where MyInterface is a basic interface (or sealed class) and there are a few possible subclasses of MyInterface.

In https://github.com/FasterXML/jackson-module-scala/issues/643, we don't really want a Map implementation class name to be written. jackson-module-scala doesn't need help with filling in a Scala Map. In fact, the class name in the serialized JSON persuades jackson-databind to try to build the Map instead of letting jackson-module-scala build it.

What I am suggesting is that when activateDefaultTyping is used, that all classes are affected (as happens now) but that we add a new method that lets users block this from happening for certain classes. It would be nice if this supported package names as well as class names. So the input would be a String or List of Strings but the individual String could be the package name and we could do a startsWith check.

### Describe the solution you'd like

Serialized JSON would not include class names where they matched a disallowed class/package name. Ideally deserialization would also ignore any classes that matched a disallowed class/package name.

something like:
`void defaultTypingIgnores(String... names)`

### Usage example

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.