Search code examples
javaspringelasticsearchspring-dataspring-data-elasticsearch

Spring Data Elasticsearch 4 - Override Object Mapper?


Previously in version 3 of Spring Data Elasticsearch, the Jackson mapper was used by default, but could be overridden to use the Metamodel object mapper, as documented here:

https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.RC1/reference/html/#elasticsearch.mapping.meta-model

I understand the Jackson mapper has been removed in version 4 and replaced with the Metamodel object mapper, as documented here:

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping

But it appears the ability to override the object mapper was removed as well. Is there indeed no way to configure the Elasticsearch global object mapper to use Jackson (or any other mapper) again? It seems like a shame to lose the flexibility that option provided.


Solution

  • No. The MappingConverter is not only used and needed for converting an entity to and from JSON, but also for converting and mapping fieldnames, dateformats and other stuff for example when CriteriaQuerys are created or when search resukts like highlights are processed. There are man places in Spring Data Elasticsearch where the mapping information for an entity is needed and Jackson cannot be used there.

    So in versions before 4.0 it was necessary to customize Jackson with jackson-annotations on the entity and the other stuff with different annotations, this has been consolidated.

    What functionality do you need that the MappingConverter (implementation of the meta model mapper) does not offer in combination with custom converters?

    Edit 05.12.2020:

    valid point from the comments: It should be possible to define a FieldNamingStrategy for an entity. I created an issue for that.