I'm using kotlin with spring boot. When i request to endpoint, that should return me LocalDateTime
object, it returns me array instead of string.
Example:
"createdAt": [
2020,
12,
16,
23,
26,
10,
932070000
]
What i expect:
"createdAt": "2020-12-16 23:26:10"
I created Jackson2ObjectMapperBuilderCustomizer
but looks like it's not working at all
@Configuration
class JacksonObjectMapperConfiguration {
companion object {
private const val dateFormat = "yyyy-MM-dd"
private const val dateTimeFormat = "yyyy-MM-dd HH:mm:ss"
}
@Bean fun jackson2ObjectMapperBuilderCustomizer(): Jackson2ObjectMapperBuilderCustomizer {
return Jackson2ObjectMapperBuilderCustomizer {
builder -> builder.simpleDateFormat(dateFormat)
builder.serializers(LocalDateSerializer(DateTimeFormatter.ofPattern(dateFormat)))
builder.serializers(LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat)))
}
}
@Bean
@Primary
fun objectMapper(): ObjectMapper =
ObjectMapper()
.registerModule(KotlinModule())
}
My build.gradle.kts
with jackson dependency
implementation(group="com.fasterxml.jackson.module", name="jackson-module-kotlin", version="2.11.3")
I want to create global LocalDateTime and LocalDate serializer for all fields in my app, any ideas how to handle it?