Search in sources :

Example 1 with Jackson2ObjectMapperBuilder

use of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder in project spring-boot by spring-projects.

the class JacksonAutoConfigurationTests method defaultObjectMapperBuilder.

@Test
public void defaultObjectMapperBuilder() throws Exception {
    this.context.register(JacksonAutoConfiguration.class);
    this.context.refresh();
    Jackson2ObjectMapperBuilder builder = this.context.getBean(Jackson2ObjectMapperBuilder.class);
    ObjectMapper mapper = builder.build();
    assertThat(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault()).isTrue();
    assertThat(mapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
    assertThat(MapperFeature.DEFAULT_VIEW_INCLUSION.enabledByDefault()).isTrue();
    assertThat(mapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
    assertThat(mapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
    assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault()).isTrue();
    assertThat(mapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
}
Also used : Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with Jackson2ObjectMapperBuilder

use of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder in project ocvn by devgateway.

the class MvcConfig method objectMapperBuilder.

@Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    //builder.featuresToEnable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    builder.serializationInclusion(Include.NON_EMPTY).dateFormat(dateFormatGmt);
    builder.serializerByType(GeoJsonPoint.class, new GeoJsonPointSerializer());
    builder.serializerByType(ObjectId.class, new ToStringSerializer());
    builder.defaultViewInclusion(true);
    return builder;
}
Also used : Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) ToStringSerializer(com.fasterxml.jackson.databind.ser.std.ToStringSerializer) GeoJsonPointSerializer(org.devgateway.ocds.web.rest.serializers.GeoJsonPointSerializer) SimpleDateFormat(java.text.SimpleDateFormat) Bean(org.springframework.context.annotation.Bean)

Aggregations

Jackson2ObjectMapperBuilder (org.springframework.http.converter.json.Jackson2ObjectMapperBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ToStringSerializer (com.fasterxml.jackson.databind.ser.std.ToStringSerializer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 GeoJsonPointSerializer (org.devgateway.ocds.web.rest.serializers.GeoJsonPointSerializer)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1