英文:
Spring Data Elastic Search 4.0.3 - List Of Dates Field
问题
以下是您要的代码部分的中文翻译:
@Field(type = FieldType.Nested, includeInParent = true, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();
这部分代码的功能是定义一个包含生日日期的列表。
请注意,您提到的错误信息是因为Spring Data没有找到将java.lang.Long
类型转换为java.time.LocalDate
类型的默认转换器。您是否需要创建自定义转换器或包装对象?这是一个值得考虑的问题,因为默认情况下,Spring Data不提供将Long
转换为LocalDate
的支持。
谢谢您的提问。
英文:
Lets say i have I have a list of birthdates
@Field(type = FieldType.Nested, includeInParent = true, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();
What is the proper way to map this using spring data without getting this error..
No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDate]
Do I really need to create a custom converter? or a wapper object?
I would think this would be supported out of the box.
Thank you in advance.
答案1
得分: 0
以下是翻译好的内容:
正确的属性注解方式应该是:
@Field(type = FieldType.Date, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();
这将会将映射条目写入为类型 date
,格式为 date
,并且存储和搜索数组将正常工作。
不好的消息是,当前版本的 Spring Data Elasticsearch 无法正确处理这个。
好消息是,我刚刚实现了对此的修复,它将包含在版本 4.0.4.RELEASE 和 4.1.0.RC1 中;这两个版本都计划在明天发布。
编辑: 这两个版本现在已经发布。
英文:
The correct way to annotate this property should be
@Field(type = FieldType.Date, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();
This would write the mappings entry as type date
and format date
, and storing and searching the array would work.
The bad news is that the current version of Spring Data Elasticsearch does not handle this correctly.
The good news is, that I just implemented the fix for this, it will be contained in versions 4.0.4.RELEASE and 4.1.0.RC1; both are planned to be released tomorrow.
Edit: both versions are released now
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论