You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but let's say our service is using multiple features that rely on using a shared ObjectMapper, like the HTTP server and elasticsearch-java.
If you provide any serialization specialization for Elasticsearch, it impacts the HTTP server, and vice-versa.
As one example, the default ObjectMapper that Micronaut provides doesn't serialize dates correctly; passing an Instant within a class results in the fields being serialized to an array, which to ES looks like we're passing multiple dates of very low values (2022 in the Unix Epoch is 2,022 seconds after Jan 1 1970). The workaround is to apply a @JsonFormat override to everyInstant:
@JsonFormat(shape = JsonFormat.Shape.STRING)
If we attempt to use write-dates-as-timestamps as documented here:
Feature description
Using the default Micronaut
ObjectMapper
is good and all when setting up Elasticsearch clients:https://github.com/micronaut-projects/micronaut-elasticsearch/blob/48e0b0c/elasticsearch/src/main/java/io/micronaut/elasticsearch/DefaultElasticsearchClientFactory.java#L83-L88
but let's say our service is using multiple features that rely on using a shared
ObjectMapper
, like the HTTP server and elasticsearch-java.If you provide any serialization specialization for Elasticsearch, it impacts the HTTP server, and vice-versa.
As one example, the default
ObjectMapper
that Micronaut provides doesn't serialize dates correctly; passing anInstant
within a class results in the fields being serialized to an array, which to ES looks like we're passing multiple dates of very low values (2022 in the Unix Epoch is 2,022 seconds after Jan 1 1970). The workaround is to apply a@JsonFormat
override to everyInstant
:If we attempt to use write-dates-as-timestamps as documented here:
micronaut-projects/micronaut-core#240 (comment)
this will fix elasticsearch-java's serialization behavior, but it will also change the http-server serialization behavior.
One solution would be to provide an alternate
ObjectMapper
from the default one for micronaut-elasticsearch. Is this a workable idea?The text was updated successfully, but these errors were encountered: