use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class WriteClassNameTest method test_writeClassName.
public void test_writeClassName() throws Exception {
Entity object = new Entity();
object.setId(123);
object.setName("jobs");
object.setAverage(3.21F);
SerializeConfig config = new SerializeConfig();
config.setAsmEnable(false);
String text = JSON.toJSONString(object, config, SerializerFeature.WriteClassName);
System.out.println(text);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class EnumTest2 method test_enum_noasm.
public void test_enum_noasm() throws Exception {
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Date date = new Date(1308841916550L);
// 1308841916550
Assert.assertEquals("1308841916550", JSON.toJSONString(date, mapping));
// "2011-06-23T23:11:56.550"
Assert.assertEquals("\"2011-06-23T23:11:56.550+08:00\"", JSON.toJSONString(date, mapping, SerializerFeature.UseISO8601DateFormat));
SerializerFeature[] features = { SerializerFeature.UseISO8601DateFormat, SerializerFeature.UseSingleQuotes };
// '2011-06-23T23:11:56.550'
Assert.assertEquals("'2011-06-23T23:11:56.550+08:00'", JSON.toJSONString(date, mapping, features));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class PropertyPreFilterClassLevelTest method test_0.
public void test_0() throws Exception {
Object[] array = { new ModelA(), new ModelB() };
SerializeConfig config = new SerializeConfig();
//
config.addFilter(//
ModelA.class, new SimplePropertyPreFilter("name"));
//
config.addFilter(//
ModelB.class, new SimplePropertyPreFilter("id"));
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{},{\"id\":1002}]", text2);
String text = JSON.toJSONString(array);
Assert.assertEquals("[{\"id\":1001},{\"id\":1002}]", text);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class ValueClassLevelTest_private method test_0.
public void test_0() throws Exception {
Object[] array = { new ModelA(), new ModelB() };
SerializeConfig config = new SerializeConfig();
//
config.addFilter(//
ModelA.class, new ValueFilter() {
@Override
public Object process(Object object, String name, Object value) {
return 30001;
}
});
//
config.addFilter(//
ModelB.class, new ValueFilter() {
@Override
public Object process(Object object, String name, Object value) {
return 20001;
}
});
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{\"id\":30001},{\"id\":20001}]", text2);
String text = JSON.toJSONString(array);
Assert.assertEquals("[{\"id\":1001},{\"id\":1002}]", text);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class IntArrayFieldTest_primitive method test_codec_null_1.
public void test_codec_null_1() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Assert.assertTrue(!mapping.isAsmEnable());
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty);
Assert.assertEquals("{\"value\":[]}", text);
}
Aggregations