Reputation: 5028
My API returns response body using org.springframework.http.ResponseEntity
I need to change the timestamp field format to a specific format.
What is the property to use in my application.properties file ?
I tried to find it over the web and I found references for other 3rd party lib and not for spring.
And if I can also define the message
field in some other format I could be great.
Current response body:
{
"timestamp": "Oct 2, 2019 3:24:32 PM",
"status": 200,
"error": "OK",
"message": "Initialization failed. cfgId doesn't exist",
"path": "/a/b/c/d/init"
}
I'm not using any 3rd party library in order to return the json, it's only
org.springframework.http.ResponseEntity
I'm looking for a general solution and not per field. I want an application.properties value to fix it.
Upvotes: 0
Views: 3216
Reputation: 2340
You can also use @JsonFormat in Jackson
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
public Date getCurrentDate() {
return new Date();
}
Upvotes: 1