Spring Data Elasticsearch默认采用了Jackson作为对象序列化方式,但是为了保持Json序列化一致性就不得不修改Spring Data Elasticsearch的序列化结果了,这里讲下如何使用的是Fastjson来序列化Spring Data Elasticsearch查询出来的数据。 Spring Data Elasticsearch中,默认会调用org.springframework.data.elasticsearch.core.DefaultResultMapper来映射ElasticSearch返回的结果,而最终序列化方法在DefaultResultMapper的父类org.springframework.data.elasticsearch.core.AbstractResultMapper的publicT mapEntity(String source, Classclazz)方法,所以只需要想办法重写mapEntity方法就行了。 在Spring Boot项目中定义下自定义的ElasticsearchTemplate就可以实现自定义ResultMapper了: @Bean("elasticsearchTemplate")
public ElasticsearchTemplate elasticsearchTempla