Search in sources :

Example 11 with JavaTimeModule

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

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 12 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project jhipster-sample-app-dto by jhipster.

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 13 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project SONG by overture-stack.

the class JsonUtils method mapper.

public static ObjectMapper mapper() {
    val specialModule = new SimpleModule();
    specialModule.addDeserializer(String.class, SpecialStringJsonDeserializer.instance);
    val mapper = new ObjectMapper().registerModule(new ParameterNamesModule()).registerModule(new Jdk8Module()).registerModule(specialModule).registerModule(new JavaTimeModule());
    mapper.disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);
    mapper.disable(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
    // Doesn't work! Fields with the value '""' (empty string) are not being deserialized as null.
    // mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
    return mapper;
}
Also used : lombok.val(lombok.val) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project api-core by ca-cwds.

the class LoggingFilter method filter.

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    LOG.info(System.getProperty(LINE_SEPARATOR) + "!!! Test Request" + System.getProperty(LINE_SEPARATOR) + "!!! URL: {}" + System.getProperty(LINE_SEPARATOR) + "!!! Method: {}" + System.getProperty(LINE_SEPARATOR) + "!!! Body: {}", requestContext.getUri(), requestContext.getMethod(), mapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestContext.getEntity()));
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project jhipster-sample-app-oauth2 by jhipster.

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)

Aggregations

JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)75 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)59 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)16 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)7 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)6 Test (org.junit.Test)6 Bean (org.springframework.context.annotation.Bean)6 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)5 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)4 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 LocalDateTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer)3 LocalTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer)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