IllegalArgumentException
thrown for mismatched subclass deserialization
#2668
Milestone
IllegalArgumentException
thrown for mismatched subclass deserialization
#2668
Current behavior:
When TypeFactory encounters a mismatch in subtypes between the property in JSON and the subclass target value, an
IllegalArgumentException
is thrown.Expected behavior:
A Jackson-specific exception is thrown that callers can handle, perhaps
JsonMappingException
, to indicate that the supplied JSON could not be mapped to the chosen target class.Use case:
This causes issues when callers are dynamically invoking Jackson based on runtime information and can't easily verify if the JSON type info value matches the correct subclass. A generic
IllegalArgumentException
hides the fact that the supplied JSON was invalid.One example of this is in Spring, when during content negotiation, Spring determines the subclass to deserialize into based on the Content-Type header of the request. If the user supplies a JSON payload for subclass A, but a Content-Type header that indicates subclass B, Spring will attempt to parse the JSON as subclass B, and fail with this
IllegalArgumentException
.If a Jackson-specific exception was surfaced, this condition could be handled. With the current behavior, an
IllegalArgumentException
is too broad of an Exception to be able to handle generically.MCVE:
The text was updated successfully, but these errors were encountered: