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()));
}
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()));
}
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()));
}
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);
}
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);
}
Aggregations