Date JsonFormat for Jackson

The default format from java.util.Date after serialized into JSON is a long number. That is not at all human readable for a Date like 07/21/2016 14:43:25.  There are many solutions to this, including pre and post formatting on the client side (AngularJS, JQuery)  as well as ObjectMapper on the Server side. But the easiest solution to me is to use com.fasterxml.jackson.annotation.JsonFormat annotation so Jackson will marshal and un-marshal the Date correctly. On the client side, only a Date picker that will restrict the user Date format will do the trick. No other coding is needed!

import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;

 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy HH:mm:ss", timezone = "America/New_York")
  @Column(name="update_date")
  private Date update_date;

Cheers!

Leave a comment