use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class ClassLevelFeatureConfigTest2 method test_0.
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.config(Model.class, SerializerFeature.BeanToArray, true);
Model model = new Model();
model.id = 1001;
Assert.assertEquals("[1001]", JSON.toJSONString(model, config));
config.config(Model.class, SerializerFeature.BeanToArray, false);
Assert.assertEquals("{\"id\":1001}", JSON.toJSONString(model, config));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class ClassLevelFeatureConfigTest3 method test_0.
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.config(Model.class, SerializerFeature.BeanToArray, false);
Model model = new Model();
model.id = 1001;
Assert.assertEquals("{\"id\":1001}", JSON.toJSONString(model, config));
config.config(Model.class, SerializerFeature.BeanToArray, true);
Assert.assertEquals("[1001]", JSON.toJSONString(model, config));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class ClassLevelFeatureConfigTest_private method test_0.
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
Model model = new Model();
model.id = 1001;
Assert.assertEquals("{\"id\":1001}", JSON.toJSONString(model, config));
config.config(Model.class, SerializerFeature.BeanToArray, true);
Assert.assertEquals("[1001]", JSON.toJSONString(model, config));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class PropertyFilterClassLevelTest method test_0.
public void test_0() throws Exception {
Object[] array = { new ModelA(), new ModelB() };
SerializeConfig config = new SerializeConfig();
//
config.addFilter(//
ModelA.class, new PropertyFilter() {
@Override
public boolean apply(Object object, String name, Object value) {
return false;
}
});
//
config.addFilter(//
ModelB.class, new PropertyFilter() {
@Override
public boolean apply(Object object, String name, Object value) {
return true;
}
});
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 NameFilterClassLevelTest_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 PascalNameFilter());
//
config.addFilter(//
ModelB.class, new NameFilter() {
@Override
public String process(Object object, String name, Object value) {
return name;
}
});
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{\"Id\":1001},{\"id\":1002}]", text2);
String text = JSON.toJSONString(array);
Assert.assertEquals("[{\"id\":1001},{\"id\":1002}]", text);
}
Aggregations