use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest1 method test_0.
public void test_0() throws Exception {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
Assert.assertEquals(0, serializer.getNameFilters().size());
Assert.assertEquals(0, serializer.getNameFilters().size());
Assert.assertEquals(0, serializer.getValueFilters().size());
Assert.assertEquals(0, serializer.getValueFilters().size());
Assert.assertEquals(0, serializer.getPropertyFilters().size());
Assert.assertEquals(0, serializer.getPropertyFilters().size());
serializer.writeWithFormat("123", null);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest2 method test_3.
public void test_3() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.config(SerializerFeature.WriteEnumUsingToString, true);
serializer.write(new A(Type.B));
Assert.assertEquals("{\"type\":\"B\"}", serializer.getWriter().toString());
A a = JSON.parseObject(serializer.getWriter().toString(), A.class);
Assert.assertEquals(a.getType(), Type.B);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSONSerializerTest2 method test_0.
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer();
int size = JSONSerializerMapTest.size(serializer.getMapping());
serializer.config(SerializerFeature.WriteEnumUsingToString, false);
serializer.config(SerializerFeature.WriteEnumUsingName, false);
serializer.write(Type.A);
Assert.assertTrue(size < JSONSerializerMapTest.size(serializer.getMapping()));
Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JavaBeanSerializerTest method test_0_s.
public void test_0_s() throws Exception {
SerializeWriter out = new SerializeWriter();
A a = new A();
a.getL0().add("A");
a.getL0().add("B");
JavaBeanSerializer serializer = new JavaBeanSerializer(A.class);
serializer.write(new JSONSerializer(out), a, null, null, 0);
Assert.assertEquals("{\"l0\":[\"A\",\"B\"]}", out.toString());
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JavaBeanSerializerTest method test_error_1_s.
public void test_error_1_s() throws Exception {
JSONException error = null;
try {
SerializeWriter out = new SerializeWriter();
JavaBeanSerializer serializer = new JavaBeanSerializer(D.class);
serializer.write(new JSONSerializer(out), new D(), null, null, 0);
} catch (JSONException e) {
error = e;
}
Assert.assertNotNull(error);
}
Aggregations