use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project uPortal by Jasig.
the class AnalyticsIncorporationComponent method initMapper.
/**
* Configure the ObjectMapper to filter out all fields on the events except those that are
* actually needed for the analytics reporting
*/
private void initMapper() {
final BeanPropertyFilter filterOutAllExcept = SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano");
this.mapper.addMixInAnnotations(PortalEvent.class, PortletRenderExecutionEventFilterMixIn.class);
final SimpleFilterProvider filterProvider = new SimpleFilterProvider();
filterProvider.addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, filterOutAllExcept);
this.portletEventWriter = this.mapper.writer(filterProvider);
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider 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);
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project tutorials by eugenp.
the class JsonFilterUnitTest method whenSerializingUsingJsonFilter_thenCorrect.
@Test
public void whenSerializingUsingJsonFilter_thenCorrect() throws JsonProcessingException {
// arrange
Author author = new Author("Alex", "Theedom");
FilterProvider filters = new SimpleFilterProvider().addFilter("authorFilter", SimpleBeanPropertyFilter.filterOutAllExcept("lastName"));
// act
String result = new ObjectMapper().writer(filters).writeValueAsString(author);
// assert
assertThat(from(result).getList("items")).isNull();
/*
{
"lastName": "Theedom"
}
*/
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project logging-log4j2 by apache.
the class AbstractJacksonFactory method newWriter.
public ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact, final boolean includeMillis) {
final SimpleFilterProvider filters = new SimpleFilterProvider();
final Set<String> except = new HashSet<>(5);
if (!locationInfo) {
except.add(this.getPropertyNameForSource());
}
if (!properties) {
except.add(this.getPropertyNameForContextMap());
}
if (!includeStacktrace) {
except.add(this.getPropertyNameForStackTrace());
}
if (includeMillis) {
except.add(getPropertyNameForInstant());
} else {
except.add(getPropertyNameForTimeMillis());
}
except.add(this.getPropertyNameForNanoTime());
filters.addFilter(Log4jLogEvent.class.getName(), SimpleBeanPropertyFilter.serializeAllExcept(except));
final ObjectWriter writer = this.newObjectMapper().writer(compact ? this.newCompactPrinter() : this.newPrettyPrinter());
return writer.with(filters);
}
use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project redisson by redisson.
the class ConfigSupport method createMapper.
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(Config.class, ConfigMixIn.class);
mapper.addMixIn(ReferenceCodecProvider.class, ClassMixIn.class);
mapper.addMixIn(AddressResolverGroupFactory.class, ClassMixIn.class);
mapper.addMixIn(Codec.class, ClassMixIn.class);
mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
mapper.addMixIn(NatMapper.class, ClassMixIn.class);
mapper.addMixIn(NameMapper.class, ClassMixIn.class);
mapper.addMixIn(NettyHook.class, ClassMixIn.class);
FilterProvider filterProvider = new SimpleFilterProvider().addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance().withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper;
}
Aggregations