Search in sources :

Example 1 with JSONSerializer

use of com.alibaba.fastjson.serializer.JSONSerializer in project dubbo by alibaba.

the class FastJsonObjectOutput method writeObject.

public void writeObject(Object obj) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(obj);
    out.writeTo(writer);
    writer.println();
    writer.flush();
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 2 with JSONSerializer

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

the class JSON method writeJSONString.

public static final // 
int writeJSONString(// 
OutputStream os, // 
Charset charset, // 
Object object, //
SerializeConfig config, //
SerializeFilter[] filters, //
String dateFormat, //
int defaultFeatures, SerializerFeature... features) throws IOException {
    SerializeWriter writer = new SerializeWriter(null, defaultFeatures, features);
    try {
        JSONSerializer serializer = new JSONSerializer(writer, config);
        if (dateFormat != null && dateFormat.length() != 0) {
            serializer.setDateFormat(dateFormat);
            serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
        }
        if (filters != null) {
            for (SerializeFilter filter : filters) {
                serializer.addFilter(filter);
            }
        }
        serializer.write(object);
        int len = writer.writeToEx(os, charset);
        return len;
    } finally {
        writer.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) SerializeFilter(com.alibaba.fastjson.serializer.SerializeFilter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 3 with JSONSerializer

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

the class JSON method writeJSONString.

public void writeJSONString(Appendable appendable) {
    SerializeWriter out = new SerializeWriter();
    try {
        new JSONSerializer(out).write(this);
        appendable.append(out.toString());
    } catch (IOException e) {
        throw new JSONException(e.getMessage(), e);
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) IOException(java.io.IOException) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 4 with JSONSerializer

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

the class JSON method toJSONString.

/**
     * @since 1.2.11
     */
public static String toJSONString(Object object, int defaultFeatures, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter((Writer) null, defaultFeatures, features);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(object);
        return out.toString();
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 5 with JSONSerializer

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

the class JSON method writeJSONString.

/**
     * @since 1.2.11 
     */
public static void writeJSONString(Writer writer, Object object, int defaultFeatures, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter(writer, defaultFeatures, features);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(object);
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)262 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)205 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)48 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 StringWriter (java.io.StringWriter)11 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)10 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)10 Map (java.util.Map)10 Date (java.util.Date)9 LinkedHashMap (java.util.LinkedHashMap)8 JSONException (com.alibaba.fastjson.JSONException)7 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 IOException (java.io.IOException)4 Color (java.awt.Color)3