Search in sources :

Example 61 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class DateFieldTest2 method test_codec.

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);
    Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 62 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class DateFieldTest3 method test_codec_null_1.

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);
    Assert.assertEquals("{\"value\":null}", text);
    V0 v1 = JSON.parseObject(text, V0.class);
    Assert.assertEquals(null, v1.getValue());
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Example 63 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class DateFieldTest3 method test_codec_no_asm.

public void test_codec_no_asm() throws Exception {
    V0 v = new V0();
    v.setValue(new Date());
    SerializeConfig mapping = new SerializeConfig();
    mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
    mapping.setAsmEnable(false);
    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
    format.setTimeZone(JSON.defaultTimeZone);
    Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimpleDateFormatSerializer(com.alibaba.fastjson.serializer.SimpleDateFormatSerializer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 64 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class DateFieldTest3 method test_codec.

public void test_codec() throws Exception {
    SerializeConfig mapping = new SerializeConfig();
    mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
    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);
    Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimpleDateFormatSerializer(com.alibaba.fastjson.serializer.SimpleDateFormatSerializer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 65 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class DateFieldTest3 method test_codec_asm.

public void test_codec_asm() throws Exception {
    V0 v = new V0();
    v.setValue(new Date());
    SerializeConfig mapping = new SerializeConfig();
    mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
    mapping.setAsmEnable(true);
    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
    format.setTimeZone(JSON.defaultTimeZone);
    Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimpleDateFormatSerializer(com.alibaba.fastjson.serializer.SimpleDateFormatSerializer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)191 Date (java.util.Date)16 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)13 SimpleDateFormat (java.text.SimpleDateFormat)12 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)10 SimpleDateFormatSerializer (com.alibaba.fastjson.serializer.SimpleDateFormatSerializer)8 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)6 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)4 HashMap (java.util.HashMap)4 DoubleSerializer (com.alibaba.fastjson.serializer.DoubleSerializer)3 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)3 SimplePropertyPreFilter (com.alibaba.fastjson.serializer.SimplePropertyPreFilter)3 AfterFilter (com.alibaba.fastjson.serializer.AfterFilter)2 BeforeFilter (com.alibaba.fastjson.serializer.BeforeFilter)2 NameFilter (com.alibaba.fastjson.serializer.NameFilter)2 PascalNameFilter (com.alibaba.fastjson.serializer.PascalNameFilter)2 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)2 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)2 BigDecimal (java.math.BigDecimal)2 DecimalFormat (java.text.DecimalFormat)2