content: package com.alibaba.fastjson.date;
  
  import com.alibaba.fastjson.JSON;
  import com.alibaba.fastjson.annotation.JSONField;
  import com.alibaba.fastjson.serializer.SerializeConfig;
  import com.alibaba.fastjson.serializer.SerializerFeature;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.Locale;
  import java.util.TimeZone;
  
  import static org.junit.jupiter.api.Assertions.assertEquals;
  
  public class DateFieldTest2 {
      @BeforeEach
      protected void setUp() throws Exception {
          JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
          JSON.defaultLocale = Locale.CHINA;
      }
  
      @Test
      public void test_codec() throws Exception {
          SerializeConfig mapping = new SerializeConfig();
  
          V0 v = new V0();
          v.setValue(new Date());
  
          String text = JSON.toJSONString(v, mapping);
  
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
          format.setTimeZone(JSON.defaultTimeZone);
          assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
      }
  
      @Test
      public void test_codec_no_asm() throws Exception {
          V0 v = new V0();
          v.setValue(new Date());
  
          SerializeConfig mapping = new SerializeConfig();
          mapping.setAsmEnable(false);
  
          String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
          format.setTimeZone(JSON.defaultTimeZone);
          assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
      }
  
      @Test
      public void test_codec_asm() throws Exception {
          V0 v = new V0();
          v.setValue(new Date());
  
          SerializeConfig mapping = new SerializeConfig();
          mapping.setAsmEnable(true);
  
          String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
          format.setTimeZone(JSON.defaultTimeZone);
          assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
      }
  
      @Test
      public void test_codec_null_asm() throws Exception {
          V0 v = new V0();
  
          SerializeConfig mapping = new SerializeConfig();
          mapping.setAsmEnable(true);
  
          String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
          assertEquals("{\"value\":null}", text);
  
          V0 v1 = JSON.parseObject(text, V0.class);
  
          assertEquals(v1.getValue(), v.getValue());
      }
  
      @Test
      public void test_codec_null_1() throws Exception {
          V0 v = new V0();
  
          SerializeConfig mapping = new SerializeConfig();
          mapping.setAsmEnable(false);
  
          String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero);
          assertEquals("{\"value\":null}", text);
  
          V0 v1 = JSON.parseObject(text, V0.class);
  
          assertEquals(null, v1.getValue());
      }
  
      public static class V0 {
          @JSONField(format = "yyyy-MM-dd")
          private Date value;
  
          public Date getValue() {
              return value;
          }
  
          public void setValue(Date value) {
              this.value = value;
          }
      }
  }
  