On Thu, Sep 19, 2019 at 6:33 AM Marc Dzaebel <[email protected]> wrote:
>
> What's about deserializing polymorhic Json into an Object? E.g.:
>
> mapper.readValue("{\"@class\":\"java.lang.Exception\",\"message\":\"Test\"}", 
> Object.class).getClass()
>
> will be a LinkedHashMap, rather than an Exception. Is there a way to achieve 
> this? I know, that the resolver could always return true, but than I'll get 
> "Missing type id" for those objects, that are not polymorphic.

I am not quite sure what the question here is -- use of `Object` as
nominal type for readValue() works the same as any other type: if
polymorphic type information is expected (via default typing, or
resolver indicating it should), type id is searched for, polymorphic
handling enabled.
But If not, "natural" mapping is used, resulting in
Map/List/Number/String/Boolean.

There is one sort of related fix going in 2.10.0:

https://github.com/FasterXML/jackson-databind/issues/1093

for writer side, however. That resolves the case of

    objectWriter.writerFor(Object.class).writeValue(....)

so that type information is included for all types if intended base
type is `Object` (similar to how `public Object value;` field would
work, instead of using actual runtime type for determination).

-+ 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10hL0MgScU4YKj_grCVJ0j%3DgGQ64dZH0nyniiPRNrRC8XQ%40mail.gmail.com.

Reply via email to