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
Formatters - add java8 java.time.LocalDate support for bindings #8707
base: main
Are you sure you want to change the base?
Conversation
@mkurz - I think this is ready for review. I have looked through the checklist, and believe all requirements to be fulfilled. As this is my first -albeit minor - contribution, I may have left something out. Please let me know if you see something missing. Thanks. |
Thanks! I will have a look until tomorrow. |
framework/src/play-java-forms/src/main/java/play/data/format/Formats.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/test/java/play/data/format/FormatsTest.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/main/java/play/data/format/Formats.java
Outdated
Show resolved
Hide resolved
framework/src/play-java-forms/src/main/java/play/data/format/Formats.java
Outdated
Show resolved
Hide resolved
@cchantep I didn't want to make too much change on my first pull-request, but it seems to me that the code would benefit from refactoring out the various classes/annotations from the 'Formats' class into their own classes. Perhaps making a 'formats' package instead. |
More refactoring in other PR I'd say |
@cchantep |
I think we can still add this to Play 2.7. |
Note from a Gitter conversation with @marcospereira:
|
@marcospereira Referring your suggestion:
I tried to make use of the spring provided formatters, converters, etc. like you suggested. However that won't work for Play - because it has it's own approach for parsing and formatting. Let's go through that step-by-step for the Therefore I don't think we can simply re-use the spring formatters. (Another note: We may would run into classloader issues when directly using |
BTW: I will push some updates later to that pull request when I have time. |
Any chance this will get merged sometime soon? |
@svaens and @mkurz this is now rebased against the master branch. I think it is good to be merged.
Looks like this is something we can optimize later, but it is beyond the scope of this PR. @svaens thanks for contributing and sorry for taking too long to move this forward. |
I will review when I find more time, thanks Marcos! |
@mkurz ping, could have just used that ;) |
@an-tex You can easily implement this yourself for now: https://www.playframework.com/documentation/2.8.x/JavaForms#Register-a-custom-DataBinder |
yep thanks I did just that ;) implicit object queryStringLocalDateBinder extends QueryStringBindable.Parsing[LocalDate](
dateString => LocalDate.parse(dateString),
_.toString,
(key: String, e: Exception) => "Cannot parse parameter %s as java.time.LocalDate: %s".format(key, e.getMessage)
) thought to give you a ping nevertheless about this open pull request |
This introduces support of LocalDate, in the way of a formatter for that type, for form binding.
Version 2.4 of playframework claimed java 8 types support. LocalDate is one of the types not yet supported.
Pull request provided in response lightbend discussion
https://discuss.lightbend.com/t/form-binding-support-for-java-8-type-localdate/852
Tests added to existing test class: framework/src/play-java-forms/src/test/scala/play/data/format/FormattersTest.java