-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow multiple date formats for date fields #1728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple date formats for date fields #1728
Conversation
830ab7e
to
9341906
Compare
cb7434a
to
b72ebd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long time no see.
Basically one thing: deprecate none
instead of removing it, this is a breaking change
src/main/java/org/springframework/data/elasticsearch/annotations/DateFormat.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/annotations/Field.java
Show resolved
Hide resolved
...g/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java
Show resolved
Hide resolved
...org/springframework/data/elasticsearch/core/convert/ElasticsearchDateConverterUnitTests.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/annotations/Field.java
Outdated
Show resolved
Hide resolved
b72ebd0
to
9dabc62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please adapt the documentation in https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/asciidoc/reference/elasticsearch-object-mapping.adoc, lines 67++ to this change?
Otherwise only cosmetic changes
src/main/java/org/springframework/data/elasticsearch/annotations/DateFormat.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/elasticsearch/annotations/Field.java
Outdated
Show resolved
Hide resolved
...org/springframework/data/elasticsearch/core/convert/ElasticsearchDateConverterUnitTests.java
Show resolved
Hide resolved
f4e47bb
to
dbc4ce9
Compare
@sothawo I have addressed all of your comments and force-pushed the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some remarks, and: there are no tests that test that the correct mapping is built for multiple formats
src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java
Outdated
Show resolved
Hide resolved
for (ElasticsearchDateConverter dateConverter : dateConverters) { | ||
try { | ||
return dateConverter.parse(s, (Class<? extends TemporalAccessor>) actualType); | ||
} catch (Exception e) { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the loop, if every registered converter fails, we should throw an error that none of the defined date formats could be used to read the value
for (ElasticsearchDateConverter dateConverter : dateConverters) { | ||
try { | ||
return dateConverter.parse(s); | ||
} catch (Exception e) { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, when all converters fail, we must error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done for both at the end of the method. Why should we do it twice?
dbc4ce9
to
7bac792
Compare
@sothawo I've done some more changes that in my opinion makes things a bit easier. Now it is no longer necessary to set |
7bac792
to
2d907ff
Compare
2d907ff
to
dada519
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change the thrown exception and add more documentation and test in a following polishing commit.
...g/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java
Show resolved
Hide resolved
👍 thank you |
Closes #1727