package space.nstart.pcp.complan

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration


@Configuration
class JacksonConfig {

    @Bean
    fun objectMapper(): ObjectMapper {
        val mapper = ObjectMapper()

        // Настраиваем формат для LocalDateTime
//        val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.zzz")

//        module.addSerializer<LocalDateTime?>(
//            LocalDateTime::class.java,
//            LocalDateTimeSerializer(formatter)
//        )
//        module.addDeserializer<LocalDateTime?>(
//            LocalDateTime::class.java,
//            LocalDateTimeDeserializer(formatter)
//        )
        mapper.registerModule(JavaTimeModule())
            .registerKotlinModule()
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

        return mapper
    }
}
