Deserialize json and at runtime get Object's propertyes

3 views
Skip to first unread message

Victor Costa

unread,
Feb 19, 2020, 4:44:11 PM2/19/20
to jackson-user
Hey, there.

I'm facing a huge problem here at my environment, I need get at runtime my Object's name for example:

Class A {
 private String bar;
}

A foo = new A();

At runtime I need exclude the field "bar" on my instance "foo" during the serialitazion without using @JsonIgnore on my class;

I'm trying the follow code by it doesn't work because I can't access the Object's name 

mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector(){
@Override
protected boolean _isIgnorable(Annotated a) {
     if(a.getName().contains("b")) { 
         return true;
     }
     boolean isIgnorable = super._isIgnorable(a);
     return isIgnorable;
    }
});

is there any way that I could do that?
Reply all
Reply to author
Forward
0 new messages