If no conversion is made, the time returned to the front end will be the ISO standard time with T. It’s not very suitable for Chinese localization.

Because Java8 can use the new LocalDate/LocalDateTime function to get the local time. Jason’s date-format configuration is invalid in application.yml because the configuration file is for Java date.

  jackson:
    date-format: "yyyy-MM-dd HH:mm:ss"
Copy the code

Use the @Configuration file below to return the time to the front end in the common YYYY-MM-DD HH: MM: SS format.

package com.demo.configuration

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter


@Configuration
class LocalDateTimeSerializerConfig {
    @Value("\${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
    private val pattern: String? = null

    @Bean
    fun localDateTimeDeserializer(a): LocalDateTimeSerializer? {
        return LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern))
    }

    @Bean
    fun jackson2ObjectMapperBuilderCustomizer(a): Jackson2ObjectMapperBuilderCustomizer? {
        return Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder ->
            builder.serializerByType(
                LocalDateTime::class.java, localDateTimeDeserializer()!! ) }}}Copy the code

The code reference can clone this

Jackson serialization LocalDate is integrated with Springboot