Search in sources :

Example 6 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter 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();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 7 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class SwaggerJsonSerializer method write.

public //
void write(//
JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();
    Json json = (Json) object;
    String value = json.value();
    out.write(value);
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) Json(springfox.documentation.spring.web.json.Json)

Example 8 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class SerializeWriterTest method test_5.

public void test_5() throws Exception {
    SerializeWriter writer = new SerializeWriter();
    writer.writeLong(-1L);
    Assert.assertEquals("-1", writer.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 9 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class SerializeWriterTest method test_1.

public void test_1() throws Exception {
    SerializeWriter writer = new SerializeWriter();
    writer.writeInt(-1);
    Assert.assertEquals("-1", writer.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 10 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class TypeUtilsTest_castToJavaBean method test_bean_2.

public void test_bean_2() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    SerializeWriter out = new SerializeWriter();
    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", "ID")));
        serializer.write(vo);
        Assert.assertEquals("{\"ID\":123}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) HashMap(java.util.HashMap) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)344 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)205 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)47 StringWriter (java.io.StringWriter)38 NameFilter (com.alibaba.fastjson.serializer.NameFilter)36 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)19 ArrayList (java.util.ArrayList)12 ListSerializer (com.alibaba.fastjson.serializer.ListSerializer)11 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)8 Date (java.util.Date)8 Map (java.util.Map)8 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)6 LinkedHashMap (java.util.LinkedHashMap)6 JSONException (com.alibaba.fastjson.JSONException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 JSONObject (com.alibaba.fastjson.JSONObject)3