-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
generic property type not resolved and custom deserializer therefore not used #155
Comments
One problem is that you can not use But looking at your class declaration, where is In the end, what is really needed is a reproducible test case, to see what is wrong, and how to resolve that. Whether older issue 190 was the same is not certain. |
Thanks for your quick answer. Github did eat up my generic declaration at is was rendered as HTML tag. I updated comment and escaped it. |
Right, noticed this is for xml module. I wish github had more flexible means to handle repo/issue-tracker relationships, since one-to-one mapping does not work too well. But it is what it is... Anyway; a small unit test would be useful, but I would suggest seeing if use of custom |
I created an isolated unit-test but there it works and I can not find the difference. I am still debugging. So far it seems that the problems come from
It gets a However, as it works in my test-case I will do some further investigation and let you know... |
@hohwille Yes, I am somewhat knowledgeable. And, alas, there are open issues for Jackson type resolution, esp. regarding type aliasing. For example this one: I did write a better type resolution library: https://github.com/FasterXML/java-classmate which handles all cases Jackson has trouble with and has no known bugs. If it does turn out that type resolution is at fault that is more difficult to resolve, since all easy fixes are done already. Fundamental problem, at this point, is that Jackson only carries mutable type resolution context (bindings), instead of properly nested set. |
When I add the actual bean causing the problem to my isolated test, I get this error:
|
I did not know about that one. I have seen that guava also did the same. There are several other implementations and I know that various other frameworks such as spring or hibernate struggle with these issues. It is really a mess that java has created here. There was actually a JSR to improve that but it has been rejected. Did you test your classmate with overriden methods that specialize the return type? There is a bug (sun and now oracle consider it a feature) that you then get two declated methods with the different return types and the order differs whether you run in debug mode or in regular mode. This bug did cost me > 20 hours. Sorry for getting off topic... |
Classmate goes well beyond what Guava does (AFAIK). The mistake many libs make (Guava included, I think), is that they assume that passing a http://www.cowtowncoder.com/blog/archives/2010/12/entry_436.html and expanded on that a bit wrt Classmate: http://www.cowtowncoder.com/blog/archives/2012/04/entry_471.html Not many developers know about classmate, but it is used by some frameworks; Hibernate is one, jDBI uses it as well I think. Many more could benefit from it, since there are many, many edge cases to cover, and starting from scratch one misses most of them. It's based on my trials and errors, so at least it covers anything I have ever used. For what that is worth. Now, most of the testing (in Classmate unit test suite) is with either basic usage, or for specific error cases I have found (including ones from Jackson). So I can't say offhand how well co-variant return type works, although I do remember adding checks for bridge methods which are generated to support those. Since the main goal is to support type resolution of POJO members, and since co-variance is sort of simple (since signature of return type is not part of the key), I would hope it works, unifying methods via overrides. But if there really are two methods defined in same class... that is an interesting anomaly. Interesting thing about debug, regular mode. I'll keep that in mind in case I see odd behavior. :-) Np for it being slightly off-topic. Happy to discuss it. |
@hohwille Back to the actual problem: while this is probably due to existing, known type resolution problem, I would be interested in an isolated reproduction. If/when we get to work on resolving these problems, it would be great to ensure good coverage. Or, if it turns out something that can not be made to work, at least document the limitation. |
I am totally with you. I only need to find some time to extract a test-case step by step that proves the error without committing non-public code. I already managed to reproduce the other bug I discovered when you define a generic type variable and then extend without using generics at all (@SuppressWarnings("rawtypes")). I could provide this till Friday. |
I finally managed to write a isolated test-case to reproduce the error.
|
Seems to be a problem of the inverse recursive generic declaration. So an easy workaround is simply switching the order of the generic declaration. |
Ok. It may also be the case that using different name for type variable can help, if the underlying issue is incorrect resolution of type aliases, especially with shadowing/renaming of given name. |
FWIW, type resolution has been rewritten in Jackson 2.7, so this is probably resolved. |
I have a bean that uses a generic that is bound to an interface. A getter uses that generic as return type.
Now I created a custom deserializer and registered for that interface that is the upper bound of the generic and expected that jackson would use this deserializer for the generic getter. However I get this error message:
So as a general example:
In Jackson I call this on my
SimpleModule
:That deserializer is used if I use the Interface directly instead of a generic.
I found that this issue was once reported as JACKSON-190 and was (partially) fixed:
http://markmail.org/message/w3oeneh5tan5tavb
As codehaus is gone I can not find out more.
In my case the issue seems still to be present in jackson (I am using 2.4.5).
The text was updated successfully, but these errors were encountered: