0

I have an endpoint in my spring boot application that returns date ranges. The backend is PostgreSQL and date columns in my database are defined as without timezone

I would like my endpoint in my spring boot application return the dates as is.

Currently, the dates get serialized with the timezone for the spring boot server.

Is there a way to configure my spring boot application to selectively ignore appending timezone data to the dates when serializing them?

the entity class is as below

public class Period{
   private Date startdate;
   private Date enddate;
}
mekbib.awoke
  • 1,094
  • 1
  • 9
  • 16

2 Answers2

1

You can use more modern java.time package, rather than outdated java.util.Date.

In your case, you can use LocalDate (or LocalDateTime). It does not contain any information about time-zone nor offset, and by default it is serialized to ISO 8601 format like 2019-12-31T23:59:59.

Max Farsikov
  • 2,451
  • 19
  • 25
0

I have just found a similar post with an elegant solution here

just adding the desired timezone as below to you application.properties file will do solve it

spring.jackson.time-zone= America/Sao_Paulo
mekbib.awoke
  • 1,094
  • 1
  • 9
  • 16