Support for ZonedDateTime
tomatelastic opened this issue · 2 comments
Description
When using a date of type ZonedDateTime, I get the error message:
jakarta.json.JsonException: Jackson exception at co.elastic.clients.json.jackson.JacksonUtils.convertException(JacksonUtils.java:39) at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:100) at co.elastic.clients.transport.rest_client.RestClientTransport.prepareLowLevelRequest(RestClientTransport.java:249) at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:153) at co.elastic.clients.elasticsearch.ElasticsearchClient.index(ElasticsearchClient.java:1121) at glib.app.lang.catalog.service.elastic.client.java.ElasticJavaApiClient.index(ElasticJavaApiClient.java:131) at glib.app.lang.catalog.service.elastic.ElasticCrudService.add(ElasticCrudService.java:324) at glib.app.lang.catalog.service.elastic.ElasticProjectServiceIT.shouldSearchForProjectsByMfId(ElasticProjectServiceIT.java:104) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type
java.time.ZonedDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: glib.app.lang.catalog.model.Product["timestamp"])
Importing the package does not help at all.
Similar discuss article here: https://discuss.elastic.co/t/new-elasticsearch-8-java-api-insert-date-time-field/311351
Same problem here, is there a solution?
Importing the package isn't enough, you have to register it in Jackson:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
JacksonJsonpMapper mapper = new JacksonJsonpMapper(objectMapper);