package com.alibaba.json.bvt.bug;

import java.util.Calendar;
import java.util.Date;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;

import junit.framework.TestCase;

public class Bug_for_issue_447 extends TestCase {

    public void test_for_issue() throws Exception {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Foo foo = new Foo();
        foo.setCreateDate(calendar.getTime());
        String date = JSON.toJSONString(foo, SerializerFeature.UseISO8601DateFormat);
        Assert.assertEquals("{\"createDate\":\"2016-04-13+08:00\"}", date);
        Foo foo2 = JSON.parseObject(date, Foo.class, Feature.AllowISO8601DateFormat);
        Assert.assertEquals("{\"createDate\":\"2016-04-13 00:00:00\"}", JSON.toJSONString(foo2, SerializerFeature.WriteDateUseDateFormat));
    }

    public static class Foo {

        private String name;
        private Date   createDate;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Date getCreateDate() {
            return createDate;
        }

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

    }
}

add testcase for issue 447. https://github.com/alibaba/fastjson/issues/447