I'm having a problem with spring data rest when I'm handling dates. In a brief, it is delaying the date in one day. For example, if I have 1111-11-11 it returns to me 1111-11-10.
There are some related post here in SO (ex1, ex2, ex3), but none of them solved the problem.
I have an entity with this LocalDate
:
@Column(nullable=true)
private LocalDate birthDate;
I also have this repository:
@RepositoryRestResource(collectionResourceRel = "person", path = "person")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long>{
}
When I save the birthDate
in the database (I'm using MySQL), it saves correctly. However, when I make this query, for example:
Person p = personRepo.findById(1L).get();
The date is fetched with one day late (just like in the example above).
I tried to implement this suggestion, that is, change the LocalDate to Date and include the Jackson annotation, but it doesn't work. I also tried to include the jackson-modules-java8
, but the problem still.
Now the most intriguing thing. As I was just testing I was including the date 1111-11-11. I changed that for today's date 2019-02-06. Then, the fetch works! At this time, I think if it was a problem with very old dates. Thus, I tried, for example, 1970-01-01, and the spring returned 1969-12-31. I realized that if I include in the database dates above 1986-01-01 everything works fine. However, if I include anything below that, I got the date one day late.
Is someone has some hint about this issue?
Thank you for your time!
EDIT: I also checked my database timezone and it's ok!
+--------------------+---------------------+--------------------+
| @@GLOBAL.time_zone | @@session.time_zone | @@system_time_zone |
+--------------------+---------------------+--------------------+
| SYSTEM | SYSTEM | -02 |
+--------------------+---------------------+--------------------+
1 row in set (0,00 sec)