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")
  private Date update_date;



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s