I have a class like the following
public class TimePeroid implements Comparable<TimePeroid>, Serializable {
private static final long serialVersionUID = -65707223409901256L;
@Expose
//@JsonFormat(pattern="HH:mm:ss")
private LocalTime start;
@Expose
//@JsonFormat(pattern="HH:mm:ss")
private LocalTime end;
//getter setter
}
At response time when I convert it into a JSON string with the help of ObjectMapper
, I get a JSON string like below
{
"start" : {"hour":6,"minute":0,"second":0,"nano":0},
"end":{"hour":18,"minute":0,"second":0,"nano":0}
}
But I need it like this
{
"start":"06:00:00",
"end":"18:00:00"
}
What I've tried until now
Solution 1
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
Solution 2
@JsonFormat(pattern="HH:mm:ss")
Solution 3
ObjectMapper mapperObj = new ObjectMapper();
mapperObj.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat df = new SimpleDateFormat("HH:mm");
mapperObj.setDateFormat(df);
None of them works. please help me on this