use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_17 method test_direct.
public void test_direct() throws Exception {
SerializeWriter out = new SerializeWriter(6);
out.config(SerializerFeature.QuoteFieldNames, true);
try {
JSONSerializer serializer = new JSONSerializer(out);
VO vo = new VO();
vo.setValue(123456789);
serializer.write(vo);
Assert.assertEquals("{\"value\":123456789}", out.toString());
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_18 method test_writer_1.
public void test_writer_1() throws Exception {
SerializeWriter out = new SerializeWriter(14);
out.config(SerializerFeature.QuoteFieldNames, true);
try {
JSONSerializer serializer = new JSONSerializer(out);
VO vo = new VO();
vo.setValue("#");
serializer.write(vo);
Assert.assertEquals("{\"value\":\"#\"}", out.toString());
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class SerializeWriterTest_19 method test_writer_1.
public void test_writer_1() throws Exception {
SerializeWriter out = new SerializeWriter(14);
out.config(SerializerFeature.QuoteFieldNames, true);
out.config(SerializerFeature.UseSingleQuotes, true);
try {
JSONSerializer serializer = new JSONSerializer(out);
VO vo = new VO();
vo.getValues().add("#");
serializer.write(vo);
Assert.assertEquals("{'values':['#']}", out.toString());
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class NameFilterTest_int method test_namefilter_1.
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 0);
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class NameFilterTest_int method test_namefilter.
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
Assert.assertTrue(value instanceof Integer);
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Bean a = new Bean();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
Aggregations