Search in sources :

Example 36 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule 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 37 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project snow-owl by b2ihealthcare.

the class SnowOwlApiConfig method createObjectMapper.

public static ObjectMapper createObjectMapper() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    final StdDateFormat dateFormat = new StdDateFormat();
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    objectMapper.setDateFormat(dateFormat);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.addMixIn(Metadata.class, MetadataMixin.class);
    objectMapper.addMixIn(MetadataHolder.class, MetadataHolderMixin.class);
    return objectMapper;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 38 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project alf.io by alfio-event.

the class BaseConfiguration method objectMapper.

@Bean
ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JavaTimeModule());
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    return mapper;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Example 39 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project eap-additional-testsuite by jboss-set.

the class Jsr310DeserializationTestCase method testDurationDeserialization.

@Test
public void testDurationDeserialization() throws Exception {
    ObjectReader reader = new ObjectMapper().registerModule(new JavaTimeModule()).readerFor(Duration.class);
    final String INPUT = "1e10000000";
    // this should return almost instantly
    Duration value = reader.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).readValue(INPUT);
    Assert.assertEquals("Didn't get the expected value.", 0, value.getSeconds());
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Duration(java.time.Duration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 40 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project Spring-5.0-By-Example by PacktPublishing.

the class RedisConfiguration method mapper.

@Bean
@Primary
public ObjectMapper mapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.registerModule(new JavaTimeModule());
    return mapper;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

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