Search in sources :

Example 6 with PropertyFilter

use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.

the class ApiService_StartTest method setUp.

@Before
public void setUp() {
    PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
    objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) ApiPermissionFilter(io.gravitee.management.service.jackson.filter.ApiPermissionFilter) Before(org.junit.Before)

Example 7 with PropertyFilter

use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.

the class ApiService_UpdateTest method setUp.

@Before
public void setUp() {
    PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
    objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) ApiPermissionFilter(io.gravitee.management.service.jackson.filter.ApiPermissionFilter) Before(org.junit.Before)

Example 8 with PropertyFilter

use of com.fasterxml.jackson.databind.ser.PropertyFilter in project tutorials by eugenp.

the class JacksonSerializationIgnoreUnitTest method givenTypeHasFilterThatIgnoresNegativeInt_whenDtoIsSerialized_thenCorrect.

@Test
public final void givenTypeHasFilterThatIgnoresNegativeInt_whenDtoIsSerialized_thenCorrect() throws JsonParseException, IOException {
    final PropertyFilter theFilter = new SimpleBeanPropertyFilter() {

        @Override
        public final void serializeAsField(final Object pojo, final JsonGenerator jgen, final SerializerProvider provider, final PropertyWriter writer) throws Exception {
            if (include(writer)) {
                if (!writer.getName().equals("intValue")) {
                    writer.serializeAsField(pojo, jgen, provider);
                    return;
                }
                final int intValue = ((MyDtoWithFilter) pojo).getIntValue();
                if (intValue >= 0) {
                    writer.serializeAsField(pojo, jgen, provider);
                }
            } else if (!jgen.canOmitFields()) {
                // since 2.3
                writer.serializeAsOmittedField(pojo, jgen, provider);
            }
        }

        @Override
        protected final boolean include(final BeanPropertyWriter writer) {
            return true;
        }

        @Override
        protected final boolean include(final PropertyWriter writer) {
            return true;
        }
    };
    final FilterProvider filters = new SimpleFilterProvider().addFilter("myFilter", theFilter);
    final MyDtoWithFilter dtoObject = new MyDtoWithFilter();
    dtoObject.setIntValue(-1);
    final ObjectMapper mapper = new ObjectMapper();
    final String dtoAsString = mapper.writer(filters).writeValueAsString(dtoObject);
    assertThat(dtoAsString, not(containsString("intValue")));
    assertThat(dtoAsString, containsString("booleanValue"));
    assertThat(dtoAsString, containsString("stringValue"));
    System.out.println(dtoAsString);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) PropertyWriter(com.fasterxml.jackson.databind.ser.PropertyWriter) MyDtoWithFilter(com.baeldung.jackson.dtos.MyDtoWithFilter) Test(org.junit.Test)

Example 9 with PropertyFilter

use of com.fasterxml.jackson.databind.ser.PropertyFilter in project drill by axbaretto.

the class DefaultSqlHandler method log.

protected void log(final String name, final PhysicalPlan plan, final Logger logger) throws JsonProcessingException {
    if (logger.isDebugEnabled()) {
        PropertyFilter filter = new SimpleBeanPropertyFilter.SerializeExceptFilter(Sets.newHashSet("password"));
        String planText = plan.unparse(context.getLpPersistence().getMapper().writer(new SimpleFilterProvider().addFilter("passwordFilter", filter)));
        logger.debug(name + " : \n" + planText);
    }
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter)

Example 10 with PropertyFilter

use of com.fasterxml.jackson.databind.ser.PropertyFilter in project gravitee-management-rest-api by gravitee-io.

the class ApiService_DeleteTest method setUp.

@Before
public void setUp() {
    PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
    objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) PropertyFilter(com.fasterxml.jackson.databind.ser.PropertyFilter) ApiPermissionFilter(io.gravitee.management.service.jackson.filter.ApiPermissionFilter) Before(org.junit.Before)

Aggregations

PropertyFilter (com.fasterxml.jackson.databind.ser.PropertyFilter)13 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)11 ApiPermissionFilter (io.gravitee.management.service.jackson.filter.ApiPermissionFilter)9 Before (org.junit.Before)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)2 MyDtoWithFilter (com.baeldung.jackson.dtos.MyDtoWithFilter)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)1 BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)1 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)1 PropertyWriter (com.fasterxml.jackson.databind.ser.PropertyWriter)1 GraviteeMapper (io.gravitee.definition.jackson.datatype.GraviteeMapper)1 Path (io.gravitee.definition.model.Path)1 Policy (io.gravitee.definition.model.Policy)1 io.gravitee.management.model (io.gravitee.management.model)1 Api (io.gravitee.repository.management.model.Api)1 Membership (io.gravitee.repository.management.model.Membership)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1