use of com.alibaba.fastjson.serializer.SerializeFilter 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.SerializeFilter in project fastjson by alibaba.
the class Issue204 method test_for_issue.
public void test_for_issue() throws Exception {
VO vo = new VO();
SerializeFilter filter = null;
JSON.toJSONString(vo, SerializeConfig.getGlobalInstance(), filter);
JSON.toJSONString(vo, SerializeConfig.getGlobalInstance(), new SerializeFilter[0]);
}
use of com.alibaba.fastjson.serializer.SerializeFilter in project fastjson by alibaba.
the class EnumFieldsTest8 method test_enum.
public void test_enum() throws Exception {
Model model = new Model();
model.t1 = Type.A;
model.t2 = null;
ValueFilter valueFilter = new ValueFilter() {
public Object process(Object object, String name, Object value) {
return value;
}
};
SerializeFilter[] filters = { valueFilter };
String text = //
JSON.toJSONString(//
model, //
SerializeConfig.getGlobalInstance(), filters, null, //
0, //
SerializerFeature.QuoteFieldNames, //
SerializerFeature.BrowserCompatible, SerializerFeature.WriteEnumUsingName);
Assert.assertEquals("{\"t1\":\"A\"}", text);
}
use of com.alibaba.fastjson.serializer.SerializeFilter in project fastjson by alibaba.
the class JSON method toJSONString.
/**
* @since 1.2.9
* @return
*/
public static //
String toJSONString(//
Object object, //
SerializeConfig config, //
SerializeFilter[] filters, //
String dateFormat, //
int defaultFeatures, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter(null, defaultFeatures, features);
try {
JSONSerializer serializer = new JSONSerializer(out, 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);
return out.toString();
} finally {
out.close();
}
}
Aggregations