Ignore JsontypeInfo

1,006 views
Skip to first unread message

Neha Goyal

unread,
Dec 28, 2015, 3:05:45 PM12/28/15
to jackso...@googlegroups.com
I have a third party class which uses JsonTypeInfo to serialize the type info into a property named data. In the serialized JSON, i do not want the type info to appear. Sadly, I don't have control over the third party class. Is there a way to ignore this field?

@JsonTypeInfo(
use = Id.NAME,
include = As.PROPERTY,
property =
"data"
)
public abstract class Data {
}

class TestData extends Data {
    private String name;
    //Getters and setters, constructors etc
}
TestData testData = new TestData();
testData.setName("randomName");
ObjectMapper mapper = new ObjectMapper();
String output = mapper.writeValueAsString(testData);
//output = {"data": "TestData", "name": "randomName"}
//I don't want data field
Thanks,
Neha

da...@bakins-bits.com

unread,
Dec 28, 2015, 9:57:35 PM12/28/15
to jackson-user
Don't know if this works, but did you try to see if a mixin will override it?  I've used them to great effect ...

Tatu Saloranta

unread,
Dec 28, 2015, 10:39:16 PM12/28/15
to jackson-user
Mix-ins would be the usual answer, yes.

If that does not work, sub-classing `JacksonAnnotationIntrospector`, and overriding method that looks for `@JsonTypeInfo`, to hide it, would be the way to go.

-+ Tatu +-


On Mon, Dec 28, 2015 at 6:57 PM, <da...@bakins-bits.com> wrote:
Don't know if this works, but did you try to see if a mixin will override it?  I've used them to great effect ...

--
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 post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neha Goyal

unread,
Dec 29, 2015, 2:16:18 PM12/29/15
to jackso...@googlegroups.com
Had already tried MixIn, wasn't really solving my issue.
Thanks Tatu, subclassing JacksonAnnotationIntrospector and overriding method works just perfectly for me.
Reply all
Reply to author
Forward
0 new messages