如何使Spring Data Elasticsearch与java.time.LocalDateTime一起使用以获取日期

如何使Spring Data Elasticsearch与java.time.LocalDateTime一起使用以获取日期,第1张

如何使Spring Data Elasticsearch与java.time.LocalDateTime一起使用以获取日期

检查https://github.com/spring-projects/spring-data-elasticsearch/wiki/Custom-
ObjectMapper
添加

JavaTimeModule
到您的中
ObjectMapper

@Configurationpublic class ElasticSearchConfiguration {  @Bean  public ElasticsearchTemplate elasticsearchTemplate(Client client) {    return new ElasticsearchTemplate(client, new CustomEntityMapper());  }  public static class CustomEntityMapper implements EntityMapper {    private final ObjectMapper objectMapper;    public CustomEntityMapper() {      objectMapper = new ObjectMapper();      objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);      objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);      objectMapper.registerModule(new CustomGeoModule());      objectMapper.registerModule(new JavaTimeModule());    }    @Override    public String mapToString(Object object) throws IOException {      return objectMapper.writevalueAsString(object);    }    @Override    public <T> T mapToObject(String source, Class<T> clazz) throws IOException {      return objectMapper.readValue(source, clazz);    }  }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5007779.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存