In as Spring Boot app, I am reading LocalDate
from a JSON in dd/MM/yyyy
format e.g. 15/03/2009 and while reading, I created them to a request. The format in the request is dd/MM/yyyy
.
*ProductRequest:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private LocalDate buyingDate;
And then I save the date fields to database via my Entity. It also has the same format as shown below:
*ProductEntity:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private LocalDate buyingDate;
But the data in the database is shown in yyyy-MM-dd
format. I think it is default format for LocalDate
, but I need to be clarified about these points: Could you helps me please?
1. Does LocalDate
always kept in yyyy-MM-dd
format in the database independently from it had in JSON file and in Request?
2. As far as I see, the format while reading the data to ProductRequest
is related to the usage when displaying data using this class (ProductRequest). IS that true?
3. Is there any need to use @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
for the date field in ProductEntity
? As far as I see, it does not make any sense for the format when saving to database. So, if we do not display or use date field from this entity, then there is no need to use format annotation. Is that true?