polymorphic deserialization based on existence of a key

21 views
Skip to first unread message

Reji Mathews

unread,
Jan 6, 2022, 1:58:07 PM1/6/22
to jackson-user
Hello !

I have a requirement where I need to select the concrete class based on presence of a key field in my json

I have a  base abstract class Activity.java which is extended by CommandActivity.java and ViewActivity.java 

Ex -
=====
Json 1

{
"command" : "abc"
"parameters" : ["ls"]
"user" : "iamuser1"
"origin" : "asia"

Json2 

{
"view" : "C001"
"resource":"XYZ"
"user" : "iamuser2"
"origin" : "US"

Based on presence of key command or view, jackson needs to select the right concrete class for deserizliation.
 
Wondering if this feature is available already in the framework? If someone had similar problem solved earlier, would be awesome if you can share the code snippet

Cheers
Reji

Tatu Saloranta

unread,
Jan 6, 2022, 4:12:16 PM1/6/22
to jackson-user
This sounds like it might be solvable using Jackson 2.12 added "infer" type:


of polymorphic deserialization?

-+ Tatu +-




Cheers
Reji

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/10a1f412-d873-450b-bf48-9bf7abb20a81n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages