Can I ask Jackson for a fully refined deserializable type?

13 views
Skip to first unread message

Bojan Tomic

unread,
Jun 8, 2019, 8:42:22 AM6/8/19
to jackson-user
Let's say I have a generic interface Inter<T>, configured via @JsonDeserialize(as = Impl.class) to always deserialize as Impl.
Can I somehow ask Jackson to fully refine the a type into its deserializable version, so that for e.g.  Inter<Inter<Number>> I get Impl<Impl<Number>>?

I'm aware of the following methods that get me halfway there:

DeserializerFactory#mapAbstractType(...)
AnnotationIntrospector#refineDeserializationType(...)

But with both of these I get Impl<Inter<Number>> and not Impl<Impl<Number>>, i.e. only one level got refined.
If there a method to get recursively refined type? Also, is any of the 2 methods I listed the correct way to refine one level?
Is this usage even supported or am I hacking at internal stuff here?

Tatu Saloranta

unread,
Jun 13, 2019, 1:44:28 AM6/13/19
to jackson-user
Unfortunately I think this is not supported. It gets quite difficult
to support multiple levels of resolution when Annotations only allow
reference to type-erased classes as values.

You may be able to override `refineDeserializationType()` to do what
you want, as you can control the logic using additional information
(as you know bit more about type structure), and doing that would make
sense to me and be supported to the degree that more advanced type
resolution is legit use case.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages