-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Should fail on trying to serialize unresolvable polymorphic subtype (not just on deserialization) #436
Comments
Addition: There is a
But the behaviour from above did not changed. |
There is no annotation currently to force failure on this case, partly because there are use cases where such serialization would work: if user configured mapper with missing types, for example; or if deserialization is handled using some other mechanism than Jackson. But I agree in that having a feature that would explicitly add checks to prevent such risky cases would be useful. I don't remember whether enough information is available to make such decision, but I hope there is; and if so, adding a check should be straight-forward. On |
Adding a check would be great. Usually I would try to create a patch, but I have to admit that I don't have a deeper understanding of the jackson libraries, sorry. To be backward compatible a new annotation would help, otherwise different options for |
Is this on the Roadmap? |
I haven't hard time to work on this and I am not aware of anyone else working on it. |
When I annotate a superclass with @JsonTypeInfo and @JsonSubTypes I do not expect that subclasses are serialized in a differnt manner. Therefor if other non-defined types are serialized I expect an exception. Example:
I have a superclass with the following annotations:
And a class using a collection that stores Animals:
This works fine as long no new subclasses are used, example output:
When another type that isn't annotated is used I don't get an exception on serialization but on deserialization - which is to late.
Instead of getting an exception the class name was used (which wasn't configured and therefore expected).
Maybe there is an option to configure Jackson to throw an exception when the type wasn't registered before, but was missed by me.
Serailized example output:
How I serialize:
How I deserialze:
Exception I get (on deserialization):
The text was updated successfully, but these errors were encountered: