Search in sources :

Example 16 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project redisson by redisson.

the class ConfigSupport method createMapper.

private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
    ObjectMapper mapper = new ObjectMapper(mapping);
    mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
    mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
    mapper.addMixIn(Config.class, ConfigMixIn.class);
    mapper.addMixIn(CodecProvider.class, ClassMixIn.class);
    mapper.addMixIn(ResolverProvider.class, ClassMixIn.class);
    mapper.addMixIn(Codec.class, ClassMixIn.class);
    mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
    mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
    FilterProvider filterProvider = new SimpleFilterProvider().addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
    mapper.setFilterProvider(filterProvider);
    mapper.setSerializationInclusion(Include.NON_NULL);
    if (classLoader != null) {
        TypeFactory tf = TypeFactory.defaultInstance().withClassLoader(classLoader);
        mapper.setTypeFactory(tf);
    }
    return mapper;
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)

Example 17 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-module-afterburner by FasterXML.

the class TestJsonFilter method testFilterOnProperty.

// Wrt [Issue#306]
public void testFilterOnProperty() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.filterOutAllExcept("a")).addFilter("b", SimpleBeanPropertyFilter.filterOutAllExcept("b"));
    assertEquals("{\"first\":{\"a\":\"a\"},\"second\":{\"b\":\"b\"}}", MAPPER.writer(prov).writeValueAsString(new FilteredProps()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 18 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-module-afterburner by FasterXML.

the class TestJsonFilter method testSimpleExclusionFilter.

public void testSimpleExclusionFilter() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.serializeAllExcept("a"));
    assertEquals("{\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 19 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind by FasterXML.

the class TestJsonFilter method testSimpleExclusionFilter.

public void testSimpleExclusionFilter() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.serializeAllExcept("a"));
    assertEquals("{\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 20 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind by FasterXML.

the class TestJsonFilter method testCheckSiblingContextFilter.

public void testCheckSiblingContextFilter() {
    FilterProvider prov = new SimpleFilterProvider().addFilter("checkSiblingContextFilter", new CheckSiblingContextFilter());
    ObjectMapper mapper = new ObjectMapper();
    mapper.setFilterProvider(prov);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.valueToTree(new CheckSiblingContextBean());
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Aggregations

FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)22 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)4 Test (org.junit.Test)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)2 JsonEncoding (com.fasterxml.jackson.core.JsonEncoding)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)1 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)1 HashMap (java.util.HashMap)1 StorelessUnivariateStatistic (org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic)1 Ignore (org.junit.Ignore)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1 MediaType (org.springframework.http.MediaType)1 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1