-
-
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
Polymorphic deserialization causes IllegalArgumentException in Jackson 2.8.1 #1339
Comments
This is by design: as exception says,
if you know for sure that Now: it may be that ideally exception should be postponed and only thrown if problem occurs, not just because it might occur. I think there may already be an issue for this; but I'll leave this open if not (if there is, I'll close one as dup). |
I understand what you are saying but the main problem is that the behavior here has changed. I have existing code written (that has worked for a while) like my example and no longer works even though I know there will not be an error when reading the value. I think that you are correct with the statement that postponing the exception to only occur if there is an actual problem would be the best solution because in many cases (such as my simple example here) code can be written so that it can be guaranteed that it won't fail. Also, it could be configurable (ie fail fast versus dynamically failing later) if you want. |
@cshannon I understand that change of behavior is unfortunate. It was not intentional, but side product of rewrite and cleanup of type handling code, resulting in more correct handling -- however, in this case omission of check had useful side. Sometimes catching potential problems early is not win-win. Anyway; the challenge in this particular case has to do with nominal type, passing that down the stack. |
I'm also running into this issue. We're using Jackson with Jersey, so the workaround of changing the requested valueType to the parent class is not available to us. |
@nsawadsky then you need to fix |
We have two endpoints, one that accepts ChildA and one that accepts ChildB. The behavior that we're trying to preserve is that on the first endpoint, ChildA will be the defaultImpl, even if the type identifier is omitted. This won't work on the second endpoint (a class cast exception would be fine if clients omit the type identifier on that endpoint) -- it's the behaviour on the first endpoint that we need to preserve (to avoid breaking existing clients). Maybe a weird case, but I just wanted to flag it as another scenario to consider. |
@nsawadsky Ok thank you for additional information. Ideally this could be improved to defer the exception throwing, as I indicated earlier: so that as long as the original declaration is self-consistent things would work until given JSON that can not work. |
Closing, same as #1488 and there is I think an issue for improving handling for this particular case, to defer throwing exception. |
There seems to be an issue trying to deserialize an object after serialization. The error message is odd because it says that the parent is not a subtype of the child, which is correct because that is of course backwards to what the relationship actually is.
Here is a very simple test case that works fine with Jackson 2.7.5 but is broken with Jackson 2.8.1.
If you run the test case with these 3 classes, the resulting stacktrace is:
The text was updated successfully, but these errors were encountered: