Search in sources :

Example 1 with LocalDateTimeSerializer

use of com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer in project litemall by linlinjava.

the class JacksonConfig method objectMapper.

@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
    objectMapper.registerModule(javaTimeModule);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}
Also used : LocalTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) LocalDateSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer) LocalDateTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 2 with LocalDateTimeSerializer

use of com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer in project litemall by linlinjava.

the class JacksonConfig method objectMapper.

@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
    objectMapper.registerModule(javaTimeModule);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}
Also used : LocalTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) LocalDateSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer) LocalDateTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 3 with LocalDateTimeSerializer

use of com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer in project litemall by linlinjava.

the class JacksonConfig method objectMapper.

@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
    ObjectMapper objectMapper = builder.createXmlMapper(false).build();
    objectMapper.registerModule(javaTimeModule);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}
Also used : LocalTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) LocalDateSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer) LocalDateTimeSerializer(com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)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 Bean (org.springframework.context.annotation.Bean)3 Primary (org.springframework.context.annotation.Primary)3