Example usage for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion

List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion.

Prototype

public ObjectMapper setSerializationInclusion(JsonInclude.Include incl) 

Source Link

Document

Method for setting defalt POJO property inclusion strategy for serialization.

Usage

From source file:org.wildfly.swarm.jaxrs.CustomJsonProvider.java

private ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    return mapper;
}

From source file:de.fraunhofer.iosb.ilt.sta.model.custom.geojson.GeoJsonSerializer.java

@Override
public String serialize(Object object) throws JsonProcessingException {
    if (object == null || !GeoJsonObject.class.isAssignableFrom(object.getClass())) {
        return null;
    }/* www .  ja v  a  2  s.c o m*/
    GeoJsonObject geoJson = (GeoJsonObject) object;
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
    mapper.addMixIn(Feature.class, FeatureMixIn.class);
    return mapper.writeValueAsString(geoJson);
}

From source file:gaffer.rest.serialisation.AbstractJacksonJsonProvider.java

protected ObjectMapper createMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
    return mapper;
}

From source file:com.servioticy.api.commons.utils.JacksonJsonProvider.java

public JacksonJsonProvider() {
    if (commonMapper == null) {
        ObjectMapper mapper = new ObjectMapper();

        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        //        mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(Visibility.ANY));
        commonMapper = mapper;/* www .  j  a  va 2s  .c  o m*/
    }
    super.setMapper(commonMapper);
}

From source file:org.jongo.marshall.jackson.configuration.PropertyModifier.java

public void modify(ObjectMapper mapper) {
    mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.setSerializationInclusion(NON_NULL);
}

From source file:org.superbiz.javaee.providers.ObjectMapperProvider.java

@Override
public ObjectMapper getContext(Class<?> type) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
    objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
    objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return objectMapper;
}

From source file:org.truelicense.v2.json.V2JsonLicenseApplicationContext.java

/**
 * Returns a new object mapper for use with {@linkplain #license licenses}
 * and {@linkplain #repositoryContext repositories}.
 * This method is normally only called once.
 * In a multi-threaded environment, it may get called more than once, but
 * then each invocation must return an object which behaves equivalent to
 * any previously returned object.//w w  w .  ja v a 2 s.c  o  m
 */
protected ObjectMapper newObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
    mapper.registerModule(new JaxbAnnotationModule());
    return mapper;
}

From source file:com.wordnik.swagger.jaxrs.json.JacksonJsonProvider.java

public JacksonJsonProvider() {
    if (commonMapper == null) {
        ObjectMapper mapper = new ObjectMapper();

        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        commonMapper = mapper;//from w  ww .  j a  v a2  s  .c  o  m
    }
    super.setMapper(commonMapper);
}

From source file:com.github.yongchristophertang.engine.web.request.JsonStringConverter.java

@Override
public String convert(Object obj) {
    ObjectMapper mapper = new ObjectMapper();
    try {//from  ww w.  j  a v  a2  s . c om
        return mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:io.springagora.store.rest.RestConfig.java

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);

    MappingJackson2HttpMessageConverter jackson = new MappingJackson2HttpMessageConverter();
    jackson.setObjectMapper(mapper);//from   ww w .  j a v  a 2 s. c  om
    jackson.setPrettyPrint(prettyPrintJSON);
    converters.add(jackson);
}