Search in sources :

Example 31 with SimpleFilterProvider

use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project openremote by openremote.

the class ValueUtil method configureObjectMapper.

public static ObjectMapper configureObjectMapper(ObjectMapper objectMapper) {
    objectMapper.setConstructorDetector(ConstructorDetector.DEFAULT).setSerializationInclusion(JsonInclude.Include.NON_NULL).configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, // see https://github.com/FasterXML/jackson-databind/issues/1547
    false).configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false).enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS).configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE).setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY).setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY).registerModule(new Jdk8Module()).registerModule(new JavaTimeModule()).registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
    objectMapper.configOverride(Map.class).setInclude(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL));
    SimpleFilterProvider filters = new SimpleFilterProvider();
    filters.setFailOnUnknownId(false);
    objectMapper.setFilterProvider(filters);
    return objectMapper;
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 32 with SimpleFilterProvider

use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project instagram-java-scraper by postaddictme.

the class MappingTest method toJson.

private String toJson(Object instance) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixIn(Object.class, PropertyFilterMixIn.class);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    SimpleBeanPropertyFilter theFilter = SimpleBeanPropertyFilter.serializeAllExcept("lastUpdated");
    FilterProvider filters = new SimpleFilterProvider().addFilter("skipLastUpdated", theFilter);
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    return objectMapper.writer(filters).writeValueAsString(instance);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)

Example 33 with SimpleFilterProvider

use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project alfresco-remote-api by Alfresco.

the class JsonJacksonTests method testSerializeMultipleObjects.

@Test
public void testSerializeMultipleObjects() throws IOException {
    final Collection<Comment> allComments = new ArrayList<Comment>();
    Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    allComments.add(aComment);
    aComment = new Comment();
    aComment.setContent("<p>I agree with the author</p>");
    allComments.add(aComment);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    jsonHelper.withWriter(out, new Writer() {

        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
            FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, allComments);
        }
    });
    assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
    assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
Also used : Comment(org.alfresco.rest.api.model.Comment) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ReturnAllBeanProperties(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 34 with SimpleFilterProvider

use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider in project logging-log4j2 by apache.

the class JacksonFactory method newWriter.

ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact) {
    final SimpleFilterProvider filters = new SimpleFilterProvider();
    final Set<String> except = new HashSet<>(2);
    if (!locationInfo) {
        except.add(this.getPropertNameForSource());
    }
    if (!properties) {
        except.add(this.getPropertNameForContextMap());
    }
    except.add(this.getPropertNameForNanoTime());
    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 35 with SimpleFilterProvider

use of com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider 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

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