title: How to deserialize date format in spring hibernate?
body: <p>i am writing a rest services where i am getting response as  in format "1448994600000" for date but i need it to give response in date,month,year format.</p>
  
  <p>if i send data by giving 12-2-2015 format it give me error</p>
  
  <blockquote>
    <p>The request sent by the client was syntactically incorrect</p>
  </blockquote>
  
  <p>In response i get "12333333333" format,i need it to response with 12-2-2015</p>
  
  <p>i have used below code to deserialize it,but its not working what is going wrong in my code,Please guide me.</p>
  
  <pre><code> import java.io.Serializable;
  import java.sql.Date;
  import java.sql.Timestamp;
  
  import javax.persistence.Column;   
  import javax.persistence.Entity;  
  import javax.persistence.GeneratedValue;  
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  import org.codehaus.jackson.annotate.JsonAutoDetect;
  import org.codehaus.jackson.annotate.JsonIgnoreProperties;
  import org.codehaus.jackson.map.annotate.JsonSerialize;  
  
  
  @JsonAutoDetect
  @Entity  
  @Table(name = "DataValueTable")  
  @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})  
  public class DataValueTable  implements Serializable {  
  
   private static final long serialVersionUID = 1L;  
  
   @Id  
   @GeneratedValue  
   @Column(name = "ID")  
   private long id;  
  
   @JsonSerialize(using=JsonDateSerializer.class)
   @Column(name = "Time")  
   private Date time;  
  
  public Date getTime() {
      return time;
  }
  
  public void setTime(Date time) {
      this.time = time;
  }
  </code></pre>
  
  <p>JsonDateSerializer.java</p>
  
  <pre><code>package com.beingjavaguys.model;
  
  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import org.codehaus.jackson.JsonGenerator;
  import org.codehaus.jackson.JsonProcessingException;
  import org.codehaus.jackson.map.JsonSerializer;
  import org.codehaus.jackson.map.SerializerProvider;
  import org.springframework.stereotype.Component;
  /**
   * Used to serialize Java.util.Date, which is not a common JSON
   * type, so we have to create a custom serialize method;.
   *
   * @author Loiane Groner
   * http://loianegroner.com (English)
   * http://loiane.com (Portuguese)
   */
  @Component
  public class JsonDateSerializer extends JsonSerializer&lt;Date&gt;{
  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
  @Override
  public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
  throws IOException, JsonProcessingException {
  String formattedDate = dateFormat.format(date);
  gen.writeString(formattedDate);
  }
  }
  </code></pre>
  
  <p>method in my controller</p>
  
  <pre><code> /* Getting List of objects in Json format in Spring Restful Services */  
   @RequestMapping(value = "/list", method = RequestMethod.GET)  
   public @ResponseBody  List getDatalist() {  
  
  
    List DataList = null;  
    try {  
  
        DataList = dataServices.getDataEntityList();  
  
    } catch (Exception e) {  
     e.printStackTrace();  
    }  
  
    return DataList;  
   }  
  </code></pre>
  
  <p>update data</p>
  
  <pre><code>@RequestMapping(value = "/updateData", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)  
       public @ResponseBody  
       Status updateData(@RequestBody DataValueTable dataObject) {  
        try {  
      //response.addHeader("Access-Control-Allow-Origin","*");
         dataServices.insertData(dataObject);  
         return new Status(1, "Data updated Successfully !");  
        } catch (Exception e) {  
         // e.printStackTrace();  
         return new Status(0, e.toString());  
        }  
        }  
  </code></pre>