Search in sources :

Example 76 with SerializeConfig

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

the class RefTest14 method test_0.

public void test_0() throws Exception {
    Group admin = new Group("admin");
    User jobs = new User("jobs");
    User sager = new User("sager");
    User sdh5724 = new User("sdh5724");
    admin.getMembers().add(jobs);
    jobs.getGroups().add(admin);
    admin.getMembers().add(sager);
    sager.getGroups().add(admin);
    admin.getMembers().add(sdh5724);
    sdh5724.getGroups().add(admin);
    sager.setReportTo(sdh5724);
    jobs.setReportTo(sdh5724);
    SerializeConfig serializeConfig = new SerializeConfig();
    serializeConfig.setAsmEnable(false);
    String text = JSON.toJSONString(admin, serializeConfig, SerializerFeature.PrettyFormat);
    System.out.println(text);
    ParserConfig config = new ParserConfig();
    config.setAsmEnable(false);
    JSON.parseObject(text, Group.class, config, 0);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ParserConfig(com.alibaba.fastjson.parser.ParserConfig)

Example 77 with SerializeConfig

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

the class DateFormatSerializerTest method test_date_4.

public void test_date_4() throws Exception {
    SerializeWriter out = new SerializeWriter();
    SerializeConfig config = new SerializeConfig();
    JSONSerializer serializer = new JSONSerializer(out, config);
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    format.setTimeZone(JSON.defaultTimeZone);
    serializer.write(new VO(format));
    Assert.assertEquals("{\"format\":\"yyyy\"}", out.toString());
    JSON.parseObject(out.toString(), VO.class);
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) SimpleDateFormat(java.text.SimpleDateFormat) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 78 with SerializeConfig

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

the class DateFormatSerializerTest method test_date_2.

public void test_date_2() throws Exception {
    SerializeWriter out = new SerializeWriter();
    SerializeConfig config = new SerializeConfig();
    JSONSerializer serializer = new JSONSerializer(out, config);
    serializer.config(SerializerFeature.WriteMapNullValue, true);
    serializer.write(new VO());
    Assert.assertEquals("{\"format\":null}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 79 with SerializeConfig

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

the class DoubleTest_custom method test_1.

public void test_1() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.put(Double.class, new DoubleSerializer("###.###"));
    Assert.assertEquals("1.123", JSON.toJSONString(1.123456789D, config));
}
Also used : DoubleSerializer(com.alibaba.fastjson.serializer.DoubleSerializer) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Example 80 with SerializeConfig

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

the class DoubleTest_custom2 method test_0.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_0() throws Exception {
    Map values = new HashMap();
    Double v = 9.00;
    values.put("double", v);
    SerializeConfig config = new SerializeConfig();
    config.put(Double.class, new DoubleSerializer(new DecimalFormat("###.00")));
    Assert.assertEquals("{\"double\":9.00}", JSON.toJSONString(values, config));
}
Also used : DoubleSerializer(com.alibaba.fastjson.serializer.DoubleSerializer) HashMap(java.util.HashMap) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) DecimalFormat(java.text.DecimalFormat) Map(java.util.Map) HashMap(java.util.HashMap)

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