Custom JacksonJsonpMapper in RestClientTransport

Hi,

I need to help with how to pass my instance of JacksonJsonpMapper to RestClientTransport in Spring Java/Kotlin project.

I have the following exception

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling. 

It is thrown by JacksonJsonpMapper in Elastic client

at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:98) ~[elasticsearch-java-8.5.3.jar:?]

Artifact jackson-datatype-jsr310 is added to the pom.xml. It is ok.
I can create my custom object mapper. It is ok.

val objectMapper = ObjectMapper().registerModule(JavaTimeModule())
val jsonpMapper = JacksonJsonpMapper(objectMapper)

In the documentation "Connecting" I see that I can pass on my instance of JacksonJsonpMapper

But how to do it in a project using Spring? Maybe by ClientConfiguration? How to pass my instance of JacksonJsonpMapper?

I've just solved it by overriding the elasticsearchClient() method

    @Bean
    override fun elasticsearchClient(restClient: RestClient): ElasticsearchClient {
        val objectMapper = ObjectMapper().registerModule(JavaTimeModule())
        val jsonpMapper = JacksonJsonpMapper(objectMapper)
        val transport = RestClientTransport(restClient, jsonpMapper)
        return ElasticsearchClient(transport);
    }

This sounds more like a Spring Data Elasticsearch question. Unfortunately I don't have detailed knowledge of the configuration process in this context. Maybe ask there?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.