Search in sources :

Example 61 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project JavaForFun by gumartinm.

the class CarControllerIntegrationTest method setup.

@Before
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).disable(MapperFeature.DEFAULT_VIEW_INCLUSION).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).enable(SerializationFeature.INDENT_OUTPUT).registerModule(new JavaTimeModule());
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Before(org.junit.Before)

Example 62 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project tutorials by eugenp.

the class TestUtil method convertObjectToJsonBytes.

/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);
    return mapper.writeValueAsBytes(object);
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 63 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project tutorials by eugenp.

the class TestUtil method convertObjectToJsonBytes.

/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);
    return mapper.writeValueAsBytes(object);
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 64 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project batfish by batfish.

the class BatfishObjectMapper method baseMapper.

/**
 * Configures all the default options for a Batfish {@link ObjectMapper}.
 */
private static ObjectMapper baseMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
    mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    // Next two lines make Instant class serialize as an RFC-3339 timestamp
    mapper.registerModule(new JavaTimeModule());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    // This line makes Java 8's Optional type serialize
    mapper.registerModule(new Jdk8Module());
    // See https://groups.google.com/forum/#!topic/jackson-user/WfZzlt5C2Ww
    // This fixes issues in which non-empty maps with keys with empty values would get omitted
    // entirely. See also https://github.com/batfish/batfish/issues/256
    mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(Include.NON_EMPTY, Include.ALWAYS));
    // This line makes Guava collections work with jackson
    mapper.registerModule(new GuavaModule());
    return mapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 65 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project core-ng-project by neowu.

the class JSONMapper method createObjectMapper.

private static ObjectMapper createObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new AfterburnerModule());
    mapper.setDateFormat(new StdDateFormat());
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
    mapper.setAnnotationIntrospector(new JSONAnnotationIntrospector());
    return mapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)81 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)65 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)17 Test (org.junit.Test)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)7 Bean (org.springframework.context.annotation.Bean)7 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)6 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)5 Before (org.junit.Before)4 Primary (org.springframework.context.annotation.Primary)4 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)3 LocalDateSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer)3 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 IOException (java.io.IOException)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 Module (com.fasterxml.jackson.databind.Module)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)2