Search in sources :

Example 11 with FilterProvider

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

the class TestJsonFilter method testSimpleInclusionFilter.

public void testSimpleInclusionFilter() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.filterOutAllExcept("a"));
    assertEquals("{\"a\":\"a\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
    // [JACKSON-504]: also verify it works via mapper
    ObjectMapper mapper = new ObjectMapper();
    mapper.setFilterProvider(prov);
    assertEquals("{\"a\":\"a\"}", mapper.writeValueAsString(new Bean()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 12 with FilterProvider

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

the class TestJsonFilter method testSimpleInclusionFilter.

public void testSimpleInclusionFilter() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.filterOutAllExcept("a"));
    assertEquals("{\"a\":\"a\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
    // [JACKSON-504]: also verify it works via mapper
    ObjectMapper mapper = new ObjectMapper();
    mapper.setFilterProvider(prov);
    assertEquals("{\"a\":\"a\"}", mapper.writeValueAsString(new Bean()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 13 with FilterProvider

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

the class TestJsonFilter method testDefaultFilter.

// defaulting, as per [JACKSON-449]
public void testDefaultFilter() throws Exception {
    FilterProvider prov = new SimpleFilterProvider().setDefaultFilter(SimpleBeanPropertyFilter.filterOutAllExcept("b"));
    assertEquals("{\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
}
Also used : FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider)

Example 14 with FilterProvider

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

the class JpaStatisticalSummaryTest method testStorelessUnivariateStatistic.

public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected) throws Exception {
    assertEquals(expected, sus.getResult(), 0.1);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    //Configure Jackson to just use fields
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
    mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
    final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));
    final ObjectWriter ssWriter = mapper.writer(filters);
    final ObjectReader ssReader = mapper.reader(sus.getClass());
    final String susString = ssWriter.writeValueAsString(sus);
    System.out.println(susString);
    final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
    assertEquals(expected, newSus.getResult(), 0.1);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) StorelessUnivariateStatistic(org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)

Example 15 with FilterProvider

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

the class AnalyticsIncorporationComponentEventSerializationTest method testMixinNoCopy.

@Test
public void testMixinNoCopy() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
    final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
    final ObjectWriter portletEventWriter = mapper.writer(filterProvider);
    final String result = portletEventWriter.writeValueAsString(createEvent());
    assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Test(org.junit.Test)

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