package com.mars.test.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Date;

/**
 * Created by USER on 2017/4/6.
 */
@Slf4j
public class TestConvertDate {

    @Test
    public void test1(){
        String json = new Gson().toJson(new Date());
        log.info("Date to json by default json =" + json);
    }

    @Test
    public void testSetDateTimeFormat(){
        String json = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(new Date());
        log.info("Date to json with format =" + json);
    }


}

@@ -105,26 +105,157 @@
 bok.
-extern.slf4j.Slf4j
+AllArgsConstructor;%0Aimport lombok.Data;%0Aimport lombok.NoArgsConstructor;%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport org.joda.time.format.DateTimeFormat
 ;%0Aim
@@ -379,16 +379,117 @@
 Date %7B%0A%0A
+    final Gson gson = new GsonBuilder()%0A            .setDateFormat(%22yyyy-MM-dd HH:mm:ss%22).create();%0A%0A
     @Tes
@@ -513,16 +513,17 @@
  test1()
+ 
 %7B%0A      
@@ -684,16 +684,17 @@
 Format()
+ 
 %7B%0A      
@@ -713,162 +713,637 @@
 n = 
-new GsonBuilder()%0A                .setDateFormat(%22yyyy-MM-dd HH:mm:ss%22).create().toJson(new Date());%0A        log.info(%22Date to json with format =%22 + json)
+gson.toJson(new Date());%0A        log.info(%22Date to json with format =%22 + json);%0A    %7D%0A%0A    @Test%0A    public void testDateTimeFormat() %7B%0A        TestData data = new TestData(%221234%22%0A                , DateTimeFormat.forPattern(%22yyyy-MM-dd HH:mm:ss%22).parseDateTime(%222017-01-24 00:00:00%22).toDate());%0A        String json = gson.toJson(data);%0A        log.info(%22Date to json with format =%22 + json);%0A        data = gson.fromJson(json,TestData.class);%0A        log.info(%22data = %22 + data.toString());%0A    %7D%0A%0A%0A    @Data%0A    @NoArgsConstructor%0A    @AllArgsConstructor%0A    class TestData %7B%0A        private String name;%0A        private Date date
 ;%0A  

add ok http post