Ignoring a field without changing the POJO class using Jackson

My POJO class has @JsonIgnorefields in the declaration, not getter and setter methods. This is a generated file, and I cannot change it much.

How to ignore this field when recording with JsonGenerator.Setting? Use @JsonIgnorefor getters and setters. But it cannot modify the created POJO class.

+1
source share
2 answers

Configuring Jackson to use field annotations only

Once annotations are placed in fields, you can configure ObjectMapperto use only field annotations, ignoring the annotations of the getters and seters methods:

ObjectMapper mapper = new ObjectMapper();    
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

Annotations for Jackson Mixons

, POJO . - , .

( ):

public interface FooMixIn {

    @JsonIgnore
    String getBar();
}

ObjectMapper, ( ) POJO:

ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
                                        .addMixIn(Foo.class, FooMixIn.class); 

:

  • , , .
  • ( , , , ) .
  • ( ): (private, protected,...) .

. .

+1

transients, , json ...

0

All Articles