title: jackson jersey json : serializing date from java to json
body: <p>my JSON output looks like: </p>
  
  <pre><code> "company":{"companyId": 0, "companyName": "OnTarget Technologies", "companyTypeId": 0, "address": null,…},
      "projectParentId": 24,
      "projectAddress":{"addressId": 26, "address1": "4750 59th street", "address2": "Apt 9C", "city": "Woodside",…},
      "taskList":[{"projectTaskId": 9, "title": "Installation of Lights", "description": "Installation of lights",…],
      "projects": null,
      "startDate": 1424322000000,
      "endDate": 1427515200000,
      "projectImagePath": null
      },
      {"projectId": 26, "projectName"
  </code></pre>
  
  <p>the data type in database for startDate and endDate is Datetime</p>
  
  <p>i get the datetime when serialized in json as a long integer.</p>
  
  <p>how do i convert it to a readable format while serializing like in a 
  format MM-dd-yyyy HH:mm:ss</p>
  
  <p>I created a provider but its not working</p>
  
  <p>here's my provider:</p>
  
  <pre><code>@Component
  @Provider
  public class MyObjectMapper implements ContextResolver&lt;ObjectMapper&gt; {
  
      private final ObjectMapper mapper;
  
      public MyObjectMapper() {
          this.mapper = createObjectMapper();
      }
  
      private static ObjectMapper createObjectMapper() {
          ObjectMapper mapper = new ObjectMapper();
          mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, true);
          mapper.setDateFormat(new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"));
          mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
          return mapper;
      }
  
      @Override
      public ObjectMapper getContext(Class&lt;?&gt; aClass) {
          return this.mapper;
      }
  }
  </code></pre>
  
  <p>I am using jacskon jersey 2.x, spring mysql database</p>
  
  <p>any idea is appreciated.</p>
  
  <p>thanks
  Sanjeev</p>