-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
TypeFactory.constructType()
does not take TypeBindings
correctly
#2796
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
Comments
I will have to read this through a few more times, perhaps create a test (complicated by the fact test needs to either copy part of jdk8 module for databind, or located in jdk8 module), but I suspect you are correct in that there is a bug. This would likely be a regression due to rewrite a few minor versions ago, to better handle type parameter substitution. And yes, it is bit of a minefield. But I think your usage is perfectly fine -- complication likely comes from type refinement needed for |
Oh, one quick comment before I have any tests: creating type for There is also the "obvious" way of JavaType type = typeFactory.constructType(new TypeReference<Optional<Set<Integer>>>() { }); but maybe there is a reason this won't work (for example, when there is need to pass components separately, fully programmatic construction). |
TypeFactory.constructType()
does not take TypeBindings
correctly
Ok, first things first: yes, I think there is a bug in |
@TheSpiritXIII Ah. Actually, the method that should work right now is But I think you are right, too, that |
I highly appreciate the very timely reply. Thank you for the prompt responses and for promising the turnaround in 2.11.2! |
Ok I think this is all fixed; added tests in |
Using Jackson version 2.11.0, suppose we want to deserialize a type as
Optional<Set<Integer>>
so I construct aJavaType
for it and deserialize.constructType
:Inside
_fromClass
,_typeCache.get(key)
return a cached entry and exits early. This simple type becomes refined with missing bindings (EMPTY_BINDINGS
is passed into_fromClass
, even though I passed explicit bindings) becauseresultType.getBindings()
is empty. Our end result is a reference typeOptional<Object>
.I deserialize and uh oh! I actually get an
Optional<ArrayList>
and I get an exception.constructParametricType
:We go inside
_fromClass
and we do not early exit because the bindings I give are passed directly in. However, there's no refining happening so we end up with with a simple typeOptional<Set<Integer>>
which causes deserialization issues because the simple type is being deserialized as if it were a bean.I deserialize and uh oh!
I was able to workaround this issue by extending
TypeFactory
and overridingconstructParametricType
and adding the refining as seen in_fromClass
, as well as thewith
builder APIs because otherwise registering a module caused me to revert back to the original TypeFactory class:Then,
If my problem was the API I was calling, please let me know kindly.
TypeFactory
is a bit of a minefield with all those deprecated and seemingly un-deprecated methods. :)Thanks
The text was updated successfully, but these errors were encountered: