use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class SerializeConfigTest method test_0.
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
Method method = SerializeConfig.class.getDeclaredMethod("createJavaBeanSerializer", Class.class);
method.setAccessible(true);
Exception error = null;
try {
method.invoke(config, int.class);
} catch (InvocationTargetException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class SerializeConfigTest2 method test_1.
public void test_1() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setTypeKey("%type");
Assert.assertEquals("%type", config.getTypeKey());
Model model = new Model();
model.value = 1001;
Assert.assertEquals("{\"%type\":\"com.alibaba.json.bvt.serializer.SerializeConfigTest2$Model\",\"value\":1001}", JSON.toJSONString(model, config, SerializerFeature.WriteClassName));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class SerializeConfigTest2_private method test_1.
public void test_1() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setTypeKey("%type");
Assert.assertEquals("%type", config.getTypeKey());
Model model = new Model();
model.value = 1001;
Assert.assertEquals("{\"%type\":\"com.alibaba.json.bvt.serializer.SerializeConfigTest2_private$Model\",\"value\":1001}", JSON.toJSONString(model, config, SerializerFeature.WriteClassName));
}
use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.
the class BeforeFilterClassLevelTest_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 BeforeFilter() {
@Override
public void writeBefore(Object object) {
this.writeKeyValue("type", "A");
}
});
//
config.addFilter(//
ModelB.class, new BeforeFilter() {
@Override
public void writeBefore(Object object) {
this.writeKeyValue("type", "B");
}
});
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{\"type\":\"A\",\"id\":1001},{\"type\":\"B\",\"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 ClassLevelFeatureConfigTest 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));
config.config(Model.class, SerializerFeature.BeanToArray, true);
Assert.assertEquals("[1001]", JSON.toJSONString(model, config));
}
Aggregations