I'm using this method to convert any object to a json string:
private String objectToJson(Object object) throws IOException {
// write JSON
StringWriter writer = new StringWriter();
ObjectMapper mapper = new ObjectMapper();
final JsonGenerator jsonGenerator = mapper.getJsonFactory().createJsonGenerator(writer);
jsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());
mapper.writeValue(jsonGenerator, object);
return writer.toString();
}
When the object being printed contains fields that are java.util.Date or jodatime's DateTime, the printed value is the number of milliseconds since the epoch. I would like, instead, to pretty-print them in a standard "HH:MM:SS" notation. How should I go about doing this?