On Mon, Jul 1, 2019 at 7:44 AM Matthieu Ghilain <[email protected]> wrote:
>
> Is it possible for jackson to deserialize an unknown payload based on some 
> type mapping information provided via a field which is present in all the 
> payloads?
>
> Constraint: the payload should not have any parent class/interface.
>
> I'd like to just do mapper.read(bytes, Object.class) and have jackson 
> deserialize it to the right class based on a common property (like 
> messageType).
>
> Thx a lot for your help!

Yes, sort of: for structures like:

{ "messageType" : "typeIdentifier",
  "value" : { .... }
}

and result of, say

public class Wrapper {
   @JsonTypeInfo(use = Id.CLASS, // or possibly NAME but then need to
map them explicitly
       property = "value"
       include = As.EXTERNAL_PROPERTY
     )
   public value Object;
}

it is possible.

Alternatively use of so-called "default typing" can achieve it too,
but it can lead to security concerns (see
https://medium.com/@cowtowncoder/on-jackson-cves-dont-panic-here-is-what-you-need-to-know-54cd0d6e8062).

But what that does (via `ObjectMapper.enableDefaultTyping(...)`) is
equivalent to enabled `@JsonTypeInfo` on categories of types (classes)
without having to add actual annotation.

-+ 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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10jW4LD3z1Ff2piqho4p8_CLxKq3ycqgjTZw3A_%2BBZC4kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to