-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add failing test for dynamic typing #60
Conversation
It seems like it works in the single object case because this line prevents |
@cowtowncoder thoughts? |
Unfortunately haven't had time to look, I can do that today. |
Add failing test for dynamic typing
... also, I know it's not of much help when you have made the mistake, but my belief is that one should never read or write non-Object JSON data by resource. |
Ok. This does look tricky. I am surprised that code should work, if type is not specified -- I would expect it then not to output type information at all, as it would be unable to determine base type of elements within |
Ah. Got it. So the test case is polymorphic in Java, but not from Jackson perspective -- and this is why specifying exact type causes issues. Had Conversely, it is not possible to simply prevent forcing of type info for all But there is some hope, perhaps for 2.6: this is an example of the problem between specifying base type to use for (polymorphic) type handling, compared to actual type to use for finding serializer. I have known there is the gap for a while, but haven't yet bumped into specific failure case. |
Interesting, for whats it's worth we haven't run into any problems using our current I see the test failure with |
Right, what happens is that without call, signature would be seen as This is not a JAX-RS specific issue (there are other related), but is due to combination of Java type erasure (instances do NOT have generic signature; only method return type and parameters do), and difference Jackson makes between polymorphic base type and instance type. Latter can be determined from value, former not. So ideally for 2.6 there would be a way to pass information to correctly handle base type (for possible polymorphic handling) without overriding instance type (where applicable). I will file a separate issue for |
Great, thanks |
@HiJon89 Forgot to mention one obvious (if not convenient) work-around that does not require changes to static class BaseList extends ArrayList<Base> { } would also prevent issues since base type is only forced for generic types, and while |
Turns out that the change to fix this in Thank you again for reporting this! |
Awesome! I'll watch for that release |
We just upgraded from Jackson 2.1.1 to Jackson 2.3.5 and encountered a regression in the way dynamic typing is handled. It seems that if you have a resource that returns a list, static typing is always used to serialize the list contents, even though the mapper has dynamic typing enabled. Returning a single object works fine (dynamic typing is used), it is only once you wrap in a list that the problem occurs. This PR adds two tests. The first one returns a single object and passes, and the second one returns a list and fails (the
z
field isn't serialized because of static typing). This test fails when running Jackson 2.3.5, 2.4.5, 2.5.1, and against master (but this behavior worked in 2.1.1).I think the issue arises because
ProviderBase
callswithType
here, and at some point it seems like that method was changed to force static typing here.I don't know enough about the internals to suggest a fix, but our workaround for now has been to add an
ObjectWriterModifier
that returnsw.withType((JavaType) null);