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();
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations