Home Deserialize to a default base type in Jackson java
Reply: 0

Deserialize to a default base type in Jackson java

nomier
1#
nomier Published in 2017-12-07 21:45:31Z

I have two objects in the format

class A { 
    private static String TYPE = "A"

    @jsonProperty("p")
    private Property1 p;
}

class B { 
    private static String TYPE = "B"

    @jsonProperty("p")
    private Property2 p;
}

and in the json format

for A

{
    type: "A",
    p: {
        type: "property1",
        name: "n",
        id: "i"
    }
}

For B

{
    type: "B",
    p: {
        type: "Property2"
        name: "n",
        id: "i",
        extraProp1: "p1",
        extraProp2: "p2"
    }
 }

I want to deserialize to class B if that fails, deserialize to class A and ignore the unknown properties

What is the best way to do that using Jackson ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.317997 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO