Search in sources :

Example 41 with SimpleFilterProvider

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);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) BeanPropertyFilter(com.fasterxml.jackson.databind.ser.BeanPropertyFilter)

Example 42 with SimpleFilterProvider

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

Example 43 with SimpleFilterProvider

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"
            }
        */
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 44 with SimpleFilterProvider

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);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) HashSet(java.util.HashSet)

Example 45 with SimpleFilterProvider

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

Aggregations

SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)51 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)17 PropertyFilter (com.fasterxml.jackson.databind.ser.PropertyFilter)12 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)11 Test (org.junit.Test)10 ApiPermissionFilter (io.gravitee.management.service.jackson.filter.ApiPermissionFilter)9 Before (org.junit.Before)9 Test (org.junit.jupiter.api.Test)7 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)6 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 HashSet (java.util.HashSet)4 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)3 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)3 lombok.val (lombok.val)3 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)3 AuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AuthenticationProperties)3 LdapAuthenticationProperties (org.apereo.cas.configuration.model.support.ldap.LdapAuthenticationProperties)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3