use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class FastjsonSockJsMessageCodec method applyJsonQuoting.
@Override
protected char[] applyJsonQuoting(String content) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.write(content);
return out.toCharArrayForSpringWebSocket();
} finally {
out.close();
}
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class JSON_toJSONStringTest method test_1.
public void test_1() throws Exception {
User user = new User();
user.setId(123);
user.setName("毛头");
SerializeConfig mapping = new SerializeConfig();
mapping.put(User.class, new JavaBeanSerializer(User.class, Collections.singletonMap("id", "uid")));
JSONSerializer serializer = new JSONSerializer(mapping);
serializer.write(user);
String jsonString = serializer.toString();
Assert.assertEquals("{\"uid\":123}", jsonString);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class RectangleTest method test_color.
public void test_color() throws Exception {
JSONSerializer serializer = new JSONSerializer();
Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Rectangle.class).getClass());
Rectangle v = new Rectangle(3, 4, 100, 200);
String text = JSON.toJSONString(v, SerializerFeature.WriteClassName);
System.out.println(text);
Rectangle v2 = (Rectangle) JSON.parse(text);
Assert.assertEquals(v, v2);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class ColorTest2 method test_color.
public void test_color() throws Exception {
JSONSerializer serializer = new JSONSerializer();
Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Color.class).getClass());
Color color = Color.RED;
String text = JSON.toJSONString(color, SerializerFeature.WriteClassName);
System.out.println(text);
Color color2 = (Color) JSON.parse(text);
Assert.assertEquals(color, color2);
}
use of com.alibaba.fastjson.serializer.JSONSerializer in project fastjson by alibaba.
the class Bug_for_JSONObject method test_0.
public void test_0() throws Exception {
JSONSerializer ser = new JSONSerializer();
ser.config(SerializerFeature.WriteClassName, true);
ser.write(new JSONObject());
}
Aggregations