package com.alibaba.json.bvt.issue_1200;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by kimmking on 22/06/2017.
 */
public class Issue1285 extends TestCase {
    public void test_for_issue() throws Exception {

        Date date = new Date();
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String json1 = "{\"createDate\":\""+df1.format(date)+"\"}";
        String json2 = "{\"createDate\":\""+df2.format(date)+"\"}";

        AccountExt accountExt = new AccountExt();
        accountExt.setCreateDate(date);

        String json = null;

        json = JSON.toJSONStringWithDateFormat(accountExt,"yyyy-MM-dd");
        assertEquals(json1, json);

        json = JSON.toJSONString(accountExt, SerializeConfig.globalInstance, null, "yyyy-MM-dd", JSON.DEFAULT_GENERATE_FEATURE);
        assertEquals(json1, json);

        json = JSON.toJSONString(accountExt);
        assertEquals(json2, json);

        json = JSON.toJSONString(accountExt, SerializeConfig.globalInstance,null,"yyyy-MM-dd",JSON.DEFAULT_GENERATE_FEATURE | SerializerFeature.FormatAnnotationFirst.getMask());
        assertEquals(json2, json);
    }

    public static class AccountExt {

        @JSONField (format="yyyy-MM-dd HH:mm:ss")
        private Date createDate;

        public Date getCreateDate() {
            return createDate;
        }

        public void setCreateDate(Date createDate) {
            this.createDate = createDate;
        }
    }


}

@@ -119,17 +119,16 @@
 NField;%0A
-%0A
 import c
@@ -266,17 +266,16 @@
 stCase;%0A
-%0A
 import j
@@ -323,16 +323,68 @@
 il.Date;
+%0Aimport java.util.Locale;%0Aimport java.util.TimeZone;
 %0A%0A/**%0A *
@@ -465,16 +465,183 @@
 tCase %7B%0A
+%0A    protected void setUp() throws Exception %7B%0A        JSON.defaultTimeZone = TimeZone.getTimeZone(%22Asia/Shanghai%22);%0A        JSON.defaultLocale = Locale.CHINA;%0A    %7D%0A%0A
     publ
@@ -776,32 +776,79 @@
 (%22yyyy-MM-dd%22);%0A
+        df1.setTimeZone(JSON.defaultTimeZone);%0A
         SimpleDa
@@ -903,24 +903,71 @@
 HH:mm:ss%22);%0A
+        df2.setTimeZone(JSON.defaultTimeZone);%0A
         Stri

add timezone in testcase