title: How to get date format response instead of millisecond from json response in springmvc and hibernate
body: <p>I am doing a sample of rest services using springmvc and hibernate,in which i am getting date response in millisecond format for date datatype,i have used below code by google search,but there is no effect of those code it results same milliseconds format.below is my code used</p>
  
  <p>controller.java</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>DataValueTable.java</p>
  
  <pre><code>  @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 = "Datatype") 
   private Date dataType;  
  
   @Column(name = "Datacategory")  
   private String dataCategory;  
  
   @Column(name = "DataValue")  
   private boolean dataValue;
       public Date getDataType() {
      return dataType;
  }
  
  public void setDataType(Date dataType) {
      this.dataType = dataType;
  }
  </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("MM-dd-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>spring-config.xml</p>
  
  <pre><code> &lt;context:component-scan base-package="com.beingjavaguys.controller" /&gt;  
   &lt;mvc:annotation-driven /&gt;  
  
   &lt;bean id="dataSource"  
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; 
    &lt;property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /&gt;  
    &lt;property name="url" value="jdbc:sqlserver://localhost;database=Sample" /&gt;  
    &lt;property name="username" value="sdsd" /&gt;  
    &lt;property name="password" value="sdsd" /&gt; 
      &lt;property name="hibernate.dialect" value="com.beingjavaguys.model.SqlServerDialectWithNvarchar" /&gt; 
   &lt;/bean&gt;  
  
  
   &lt;bean id="sessionFactory"  
   class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;  
   &lt;property name="dataSource" ref="dataSource" /&gt;  
   &lt;property name="annotatedClasses"&gt;  
   &lt;list&gt;  
     &lt;value&gt;com.beingjavaguys.model.Employee&lt;/value&gt;   
        &lt;value&gt;com.beingjavaguys.model.DataValueTable&lt;/value&gt; 
     &lt;/list&gt;  
    &lt;/property&gt;  
    &lt;property name="hibernateProperties"&gt;  
     &lt;props&gt;  
  
      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/prop&gt;  
      &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;  
     &lt;/props&gt;  
    &lt;/property&gt;  
   &lt;/bean&gt;  
  
  
   &lt;bean id="txManager"  
    class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;  
    &lt;property name="sessionFactory" ref="sessionFactory" /&gt;  
   &lt;/bean&gt;  
  
   &lt;bean id="persistenceExceptionTranslationPostProcessor"  
    class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt;  
  
   &lt;bean id="dataDao" class="com.beingjavaguys.dao.DataDaoImpl"&gt;&lt;/bean&gt;  
   &lt;bean id="dataServices" class="com.beingjavaguys.services.DataServicesImpl"&gt;&lt;/bean&gt;  
  &lt;/beans&gt;  
  </code></pre>
  
  <p>Right now i am getting response as "12312121000".I want it to display in 02-02-2015 format.Any suggestion and answers are welcomed.</p>