Search in sources :

Example 21 with FilterProvider

use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind 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 22 with FilterProvider

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

the class AnalyticsIncorporationComponentEventSerializationTest method testMixinWithCopy.

/**
     * Fails as actual output is:
     * {"@c":".PortletRenderExecutionEvent","timestamp":1371671516798,"serverId":"example.com","eventSessionId":"1234567890123_system_AAAAAAAAAAA","userName":"system","fname":"fname1","executionTimeNano":123450000,"parameters":{},"targeted":false,"usedPortalCache":false}
     */
@Ignore
@Test
public void testMixinWithCopy() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    //Clone from "shared" ObjectMapper
    mapper = mapper.copy();
    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) Ignore(org.junit.Ignore) 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