Example usage for com.fasterxml.jackson.databind ObjectMapper setFilters

List of usage examples for com.fasterxml.jackson.databind ObjectMapper setFilters

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper setFilters.

Prototype

public void setFilters(FilterProvider filterProvider) 

Source Link

Document

Convenience method that is equivalent to:
 mapper.setFilters(mapper.getSerializationConfig().withFilters(filterProvider)); 

Note that usually it is better to use method #writer(FilterProvider) ; however, sometimes this method is more convenient.

Usage

From source file:com.pressassociation.pr.filter.json.jackson.JacksonFilters.java

/**
 * Filter all serialised output via the given ObjectMapper with the given matcher.
 *//*from   w  w  w . j  a  v a  2 s.c o m*/
public static ObjectMapper filterAllOutput(ObjectMapper mapper, Matcher matcher) {
    mapper.setFilters(new SimpleFilterProvider().addFilter(FILTER_ID, new JacksonMatcherFilter(matcher)));
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
        @Override
        public Object findFilterId(Annotated a) {
            return FILTER_ID;
        }
    });
    return mapper;
}

From source file:com.pressassociation.pr.filter.json.jackson.JacksonMatcherFilterTest.java

private void assertMatchesJson(CharSequence fields, String json) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
    JacksonMatcherFilter filter = new JacksonMatcherFilter(Matcher.of(fields));
    mapper.setFilters(new SimpleFilterProvider().addFilter("test", filter));
    assertEquals(json, mapper.writeValueAsString(new PetStore()));
    assertNull("Runtime state was not cleared", filter.state.get());
}

From source file:org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpoint.java

/**
 * Configure PropertyFilter to make sure Jackson doesn't process CGLIB generated bean
 * properties./* w  w w. java2  s .c om*/
 */
private void applyCglibFilters(ObjectMapper mapper) {
    mapper.setAnnotationIntrospector(new CglibAnnotationIntrospector());
    mapper.setFilters(new SimpleFilterProvider().addFilter(CGLIB_FILTER_ID, new CglibBeanPropertyFilter()));
}

From source file:uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser.java

public static ObjectMapper createDefaultMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true);
    mapper.registerModule(getCloseableIterableDeserialiserModule());

    // Use the 'setFilters' method so it is compatible with older versions of jackson
    mapper.setFilters(getFilterProvider());
    return mapper;
}