I am converting a java bean string to JSON using Jackson version 2.7.4. However, I am facing a date format problem. Used version of Java 1.7.
Bean:
public class BaseBean {
private java.util.Date fromDate;
public Date getFromDate() {
return fromDate;
}
public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}
}
and I get below date format
{"fromDate":1465370289436}
This is not required of me. then I configured below code
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS , false);
jsonInString = objectMapper.writeValueAsString(objJava);
Then I get the format below the date in JSON:
{"fromDate":"2016-06-08T07:47:06.636+0000"}
Expected Date Format:
{"fromDate":{"date":8,"day":3,"hours":12,"minutes":48,"month":5,"seconds":9,"time":1465370289436,"timezoneOffset":-330,"year":116}}
Is there any configuration to handle it and get the expected date format in the JSON string.
source
share