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);
}
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);
}
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());
}
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));
}
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));
}
Aggregations