In my application I added REST. To test these methods I created some basic rows in my database.
When I try to use GET with an ID to get a specific row in my database I get the jackson exception.
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2019-03-11T10:14:14Z[UTC]": not a valid representation (error: Failed to parse Date value '2019-03-11T10:14:14Z[UTC]': Cannot parse date "2019-03-11T10:14:14Z[UTC]": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
My object that I try to make has a field
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date published;
And the constructor that gets called is
public something(Date published) {
this.published = published;
}
I read in a StackOverflow question I should add the
@JsonType(pattern="")
above the field 'Published' but I can't seem to find what I need to import to get that annotation to work.
EDIT: Thanks to the answer from SHAHAKASH I managed to add the annotation after all.
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = TimeZone.getDefault(), locale = Locale.getDefault())
However I'm having two issues with this, one is that it won't allow me to keep the timezone and the locale. So removing those lets my program run
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS")
Which gives me the error:
Cannot deserialize value of type `java.util.Date` from String "2019-03-11T10:14:14Z[UTC]": expected format "yyyy-MM-dd'T'HH:mm:ss.SSS"
Obviously meaning my format is wrong. I'm having lots of troubles to find the correct format of my Date.