OBPIH-6965 add data binding support for java.time classes#5023
OBPIH-6965 add data binding support for java.time classes#5023
Conversation
|
|
||
| private Date parseDateShipped(String date) { | ||
| return date ? Constants.DELIVERY_DATE_FORMATTER.parse(date) : null | ||
| return DateUtil.asDate(date, Constants.DELIVERY_DATE_FORMATTER) |
There was a problem hiding this comment.
This is a fix for https://pihemr.atlassian.net/browse/OBS-1831. I wanted something real to test my changes against so figured I'd fix the issue while I was at it.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5023 +/- ##
============================================
+ Coverage 7.75% 7.84% +0.08%
- Complexity 860 876 +16
============================================
Files 613 624 +11
Lines 42622 42815 +193
Branches 10350 10375 +25
============================================
+ Hits 3306 3357 +51
- Misses 38822 38955 +133
- Partials 494 503 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // TODO: Don't add more dates here! We should refactor all usages of these constants to instead use the | ||
| // DateTimeFormatter constants in DateUtil. The backend should always return dates in the same format so that | ||
| // the frontend can easily parse response objects. Let the frontend decide what the display format of each | ||
| // individual field should be. |
There was a problem hiding this comment.
my idea here is that we should always use the same format when returning dates to the frontend, and then let the frontend format the dates for display.
As such, I hope we can eventually remove most of these from the backend and simply call toString() on the Instant/LocalDate datatypes in the toJson() method of our Domains/DTOs/CommandObjects.
As for how to parse date on the frontend, Alan did a discovery that is quite relevant
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-6965
Description:
Add support for java.time.Instant and java.time.LocalDate data binding. With this change we can now use those data types in our Domain classes and DTO/Command objects. This is important because java.util.Date is functionally deprecated as of Java 8, so going forward we should stop using it if possible.
See my other PR for an example implementation that uses this change: #5022
This is based off the discovery work I did on java.time in OBPIH-6916. I encourage you to read that if you want some background information on this change.