Search in sources :

Example 56 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpoint method configureJsonMapper.

/**
 * Configure Jackson's {@link JsonMapper} to be used to serialize the
 * {@link ConfigurationProperties @ConfigurationProperties} objects into a {@link Map}
 * structure.
 * @param builder the json mapper builder
 * @since 2.6.0
 */
protected void configureJsonMapper(JsonMapper.Builder builder) {
    builder.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    builder.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    builder.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
    JsonMapper.builder();
    builder.configure(MapperFeature.USE_STD_BEAN_NAMING, true);
    builder.serializationInclusion(Include.NON_NULL);
    applyConfigurationPropertiesFilter(builder);
    applySerializationModifier(builder);
    builder.addModule(new JavaTimeModule());
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)

Example 57 with JavaTimeModule

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

the class RestExtensions method givenUnauthenticatedRequest.

public static RequestSpecification givenUnauthenticatedRequest(String api) {
    if (INITIALIZE_ONCE.compareAndSet(false, true)) {
        // change Base URI if defined as sysarg
        final String serverLocation = System.getProperty("test.server.location");
        if (!Strings.isNullOrEmpty(serverLocation)) {
            RestAssured.baseURI = serverLocation;
        }
        RestAssured.config = RestAssuredConfig.config().objectMapperConfig(ObjectMapperConfig.objectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {

            @Override
            public com.fasterxml.jackson.databind.ObjectMapper create(Type arg0, String arg1) {
                com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
                mapper.registerModule(new JavaTimeModule());
                // bbanfai: added date format
                final StdDateFormat dateFormat = new StdDateFormat();
                dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                mapper.setDateFormat(dateFormat);
                mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                return mapper;
            }
        })).logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails());
    }
    Preconditions.checkArgument(api.startsWith("/"), "Api param should start with a forward slash: '/'");
    return given().port(getPort()).basePath(CONTEXT + api);
}
Also used : ContentType(io.restassured.http.ContentType) Type(java.lang.reflect.Type) Jackson2ObjectMapperFactory(io.restassured.mapper.factory.Jackson2ObjectMapperFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat)

Example 58 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class JsonFormatter method format.

public String format(Object value) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.registerModule(new JavaTimeModule());
    return mapper.writer().writeValueAsString(Objects.requireNonNull(value));
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 59 with JavaTimeModule

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

the class Binder method initialize.

private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
    if (mapper instanceof XmlMapper) {
        ((XmlMapper) mapper).setDefaultUseWrapper(false);
        ((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with(introspector);
    mapper.getSerializationConfig().with(introspector);
    mapper.registerModule(new AfterburnerModule());
    mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ExtModule());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
    mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    // todo remove after kernel cleanup
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    if (skipInputNulls)
        mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
    if (!nonNullInclusion)
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    modules.forEach(mapper::registerModule);
    if (defaultTyping)
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ExtModule(oap.json.ext.ExtModule)

Example 60 with JavaTimeModule

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

the class Jsr310DeserializationTestCase method testInstantDeserialization.

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

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