ObjectMapper SetDateFormat() is not working
<p>I have used ObjectMapper to map a object to Json String.
I have date Fields in the object to format the date i have used the below code but it is not formatting as expected.</p>

<p>My Json String:</p>

<pre><code>{"leaveRequestId":51,"reason":"xdvfsgf","leaveFromDate":"2016-07-13","leaveToDate":"2016-07-15","leaveTypeId":9,"statusId":1,"instanceId":"7527","createdBy":"pramod","createdOn":"2016-07-07","modifiedBy":null,"modifiedOn":null}
</code></pre>

<p>I am using the below code:</p>

<pre><code>@RequestMapping(value="/getLeaveRequest", method = RequestMethod.GET)
@ResponseBody
public  String getLeaveRequest( int leaveRequestId) throws Exception {
 DAOFactory obj_daofactory=new DAOFactory();
 ObjectMapper mapper = new ObjectMapper();
 SimpleDateFormat df = new SimpleDateFormat("yyyy-MMM-dd");
 mapper.setDateFormat(df);

 LeaveRequest leaveRequest = obj_daofactory.getLeaveRequestDao().findByLeaveRequestId(leaveRequestId);
 if(leaveRequest.getLeaveRequestId() == 0){
     return "No data found";
 } else {
     System.out.println(leaveRequest.getLeaveFromDate().toString());
     String jsonInString = mapper.writeValueAsString(leaveRequest);
     System.out.println(jsonInString);
     return jsonInString;
    }
}
</code></pre>

<p>MY Expected OutPut:</p>

<pre><code>{"leaveRequestId":45,"reason":"test","leaveFromDate":"2016-Jul-07","leaveToDate":"2016-Jul-08","leaveTypeId":9,"statusId":1,"instanceId":"test1","createdBy":"deepak.paul@muraai.com","createdOn":"2016-Jul-07","modifiedBy":"pramod","modifiedOn":"2016-Jul-08"}
</code></pre>

<p>Date must be in the "2016-Jul-07" format</p>

<p>LeaveRequest.java</p>

<pre><code>import java.util.Date;

public class LeaveRequest {
    private int leaveRequestId;
    private String reason;
    private Date leaveFromDate;
    private Date leaveToDate;
    private int leaveTypeId;
    private int statusId;
    private String instanceId;
    private String createdBy;
    private Date createdOn;
    private String modifiedBy;
    private Date modifiedOn;

    public LeaveRequest() {

    }

    public LeaveRequest(int leaveRequestId, String reason, Date leaveFromDate, Date leaveToDate,int leaveTypeId,int statusId, String instanceId,
            String createdBy, Date createdOn, String modifiedBy, Date modifiedOn)   {
        this.leaveRequestId=leaveRequestId;
        this.reason=reason;
        this.leaveFromDate=leaveFromDate;
        this.leaveToDate=leaveToDate;
        this.leaveTypeId=leaveTypeId;
        this.statusId=statusId;
        this.instanceId=instanceId;
        this.createdBy=createdBy;
        this.createdOn=createdOn;
        this.modifiedBy=modifiedBy;
        this.modifiedOn=modifiedOn;
    }
    public LeaveRequest(String reason, Date leaveFromDate, Date leaveToDate,int leaveTypeId,int statusId, String instanceId,
            String createdBy, Date createdOn)   {
        this.reason=reason;
        this.leaveFromDate=leaveFromDate;
        this.leaveToDate=leaveToDate;
        this.leaveToDate=leaveToDate;
        this.leaveTypeId=leaveTypeId;
        this.statusId=statusId;
        this.instanceId=instanceId;
        this.createdBy=createdBy;
        this.createdOn=createdOn;
    }
    public int getLeaveRequestId() {
        return leaveRequestId;
    }

    public void setLeaveRequestId(int leaveRequestId) {
        this.leaveRequestId = leaveRequestId;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public Date getLeaveToDate() {
        return leaveToDate;
    }

    public void setLeaveToDate(Date leaveToDate) {
        this.leaveToDate = leaveToDate;
    }

    public Date getLeaveFromDate() {
        return leaveFromDate;
    }

    public void setLeaveFromDate(Date leaveFromDate) {
        this.leaveFromDate = leaveFromDate;
    }

    public int getStatusId() {
        return statusId;
    }

    public void setStatusId(int statusId) {
        this.statusId = statusId;
    }

    public int getLeaveTypeId() {
        return leaveTypeId;
    }

    public void setLeaveTypeId(int leaveTypeId) {
        this.leaveTypeId = leaveTypeId;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public Date getModifiedOn() {
        return modifiedOn;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    public String getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }

}
</code></pre>