On Thu, Mar 8, 2018 at 5:58 PM, Bojan Tomic <veg...@gmail.com> wrote:
> Given the following class:
>
> public static class Container {
>
>  private AbstactType item;
>
>  @JsonDeserialize(as = ConcreteType.class)
>  public AbstactType getItem() {
>  return item;
>  }
> }
>
>
> I'm now trying to analyze the type to discover the overridden deserializable
> type:
>
> BeanDescription desc =
> objectMapper.getDeserializationConfig().introspect(containerType);
> //containerType represents the Container class
> BeanPropertyDefinition prop = desc.findProperties().get(0);
> prop.getPrimaryType(); // nope... gets me AbstractType
> prop.getGetter().getType(); // still nope... AbstractType again :(
>
>
> I'd expect one of the methods above to return ConcreteType? Does my
> reasoning make sense? Is this doable?

Logical type of the property is not modified at introspection; type
refinement only occurs when actually looking
for serializer / deserializer. But refinement itself is accessible
through `AnnotationIntrospector`, which has methods
`refineDeserializationType` and `refineSerializationType`. To call
those you need to get accessor from `prop`
(I forget name of getter but it should be there).

> On a related note, is it possible to ask Jackson is the type is
> deserializable or if it needs extra type info?
> E.g. most abstract types need extra info to be deserialized, but built-in
> abstract types like List or Map do not (as Jackson already has defaults for
> those)?

No extra type info is used, but there is default mapping of abstract
types to concrete types.
(type info would refer to polymorphic handling which is bit different).
It is possible to add such mappings for abstract types via Modules;
`SimpleModule` has method
`addAbstractTypeMapping(...)`; so you can register `ConcreteType` as
the implementation of `AbstractType`
without annotations.

Hope this helps,

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to