0

In the http request JSON data, the releaseDate is 10/11/2022 in String format. After spring boot converts the JSON request into java bean. the releaseDate is converted to Mon Oct 10 18:00:00 MDT 2022. When I save it in the sql table, the releaseDate was changed to 10/10/2022. How should I change the setting? Thanks.

@PutMapping("/release/statusChange/{id}")
   public BasicReleaseDto updateReleaseBeanStatus(@PathVariable long id, @RequestBody ReleaseBean newReleaseBean) {
@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy")
@Column(name = "RELEASE_DATE")
java.util.Date releaseDate;
PLee
  • 393
  • 9
  • 26
  • is your db in a different timezone than your app? – Sreek521 Oct 07 '22 at 19:35
  • @Sreek521 no. they are the same zone – PLee Oct 07 '22 at 19:41
  • please check the below link once. This will allow you to set a common time zone across your application. If your database is also in the same time zone this should help. https://stackoverflow.com/questions/46151633/how-to-make-default-time-zone-apply-in-spring-boot-jackson-date-serialization#:~:text=31,a%20config%20class%3A – Sreek521 Oct 07 '22 at 19:53

2 Answers2

0

use this:

@Temporal(value = TemporalType.TIMESTAMP)
private Date ;
0

Use the data type below if you want to reflect the time in SQL. If you have changed the data type once created with the different data type, you have to delete the column first and then run your application, it will automatically create the new column with the desired data type. and if it will not work then when you are doing setReleaseDate first convert it into desired data type, then set

LocalDateTime releaseDate;