title: How to serialize Long epoch date format into date using JSONObject
body: <p>I have json string payload having date in epoch (long) format.But I have to convert that into yyyyMMddHHmmss format.I'm using custom serializers where I can apply that on particular field.But the serialization is not able to apply on that field.</p>
  
  <p><strong>Test.java</strong></p>
  
  <pre><code> private static String json = "{
  
            "dcCountryCode": "US",
            "orderDate": 1517855400000
          }";
  
  
  
      @JsonSerialize(using = CustomLongSerializer.class)
      private static Long date;
  
      public static void main(String[] args) {
  
  
          JSONObject obj = new JSONObject(json);
  
          String country = obj.getString("dcCountryCode");
  
          date = obj.getLong("orderDate");
  
  
          System.out.println(country);
  
          System.out.println(date);
  
      }
  </code></pre>
  
  <p><strong>CustomLongSerializer.java</strong></p>
  
  <pre><code>
      package com.company;
  
      import com.fasterxml.jackson.core.JsonGenerator;
      import com.fasterxml.jackson.databind.SerializerProvider;
      import com.fasterxml.jackson.databind.ser.std.StdSerializer;
  
      import java.io.IOException;
      import java.text.SimpleDateFormat;
  
  
      // This is for Custom Date serializer
      public class CustomLongSerializer extends StdSerializer&lt;Long&gt; {
  
          protected CustomLongSerializer(Class&lt;Long&gt; t) {
              super(t);
          }
  
          protected CustomLongSerializer() {
              this(Long.class);
          }
  
          private static final long serialVersionUID = 1L;
  
          @Override
          public void serialize(Long value, JsonGenerator gen, SerializerProvider provider) throws IOException {
  
              SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
              gen.writeString(df.format(value));
  
          }
  
      }
  
  
  
  Expected Out put in yyyyMMddHHmmss format.
  
  But still returning epoch date format.
  
  Can anyone help me with this.
  
  </code></pre>