use of com.alibaba.fastjson.serializer.PascalNameFilter in project fastjson by alibaba.
the class PascalNameFilterTest method test_0.
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.getNameFilters().add(new PascalNameFilter());
VO vo = new VO();
vo.setId(123);
vo.setName("wenshao");
serializer.write(vo);
Assert.assertEquals("{\"Id\":123,\"Name\":\"wenshao\"}", serializer.toString());
serializer.close();
}
use of com.alibaba.fastjson.serializer.PascalNameFilter 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);
}
use of com.alibaba.fastjson.serializer.PascalNameFilter in project fastjson by alibaba.
the class PascalNameFilterTest_1 method test_0.
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.getNameFilters().add(new PascalNameFilter());
Map<String, Object> vo = new LinkedHashMap<String, Object>();
vo.put("", 123);
vo.put(null, "wenshao");
serializer.write(vo);
Assert.assertEquals("{\"\":123,null:\"wenshao\"}", serializer.toString());
serializer.close();
}
use of com.alibaba.fastjson.serializer.PascalNameFilter in project fastjson by alibaba.
the class NameFilterClassLevelTest 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