public static String toJSONString( Object object, SerializeFilter[] filters, SerializerFeature... features) { SerializeWriter out = new SerializeWriter(); try { JSONSerializer serializer = new JSONSerializer(out); for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) { serializer.config(feature, true); } serializer.config(SerializerFeature.WriteDateUseDateFormat, true); setFilter(serializer, filters); serializer.write(object); return out.toString(); } finally { out.close(); } }
/** @since 1.1.14 */ public static String toJSONStringWithDateFormat( Object object, String dateFormat, SerializerFeature... features) { SerializeWriter out = new SerializeWriter(); try { JSONSerializer serializer = new JSONSerializer(out); for (SerializerFeature feature : features) { serializer.config(feature, true); } serializer.config(SerializerFeature.WriteDateUseDateFormat, true); if (dateFormat != null) { serializer.setDateFormat(dateFormat); } serializer.write(object); return out.toString(); } finally { out.close(); } }
public static void writeJSONStringTo( Object object, Writer writer, SerializerFeature... features) { SerializeWriter out = new SerializeWriter(writer); try { JSONSerializer serializer = new JSONSerializer(out); for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) { serializer.config(feature, true); } serializer.write(object); } finally { out.close(); } }
public static byte[] toJSONBytes(Object object, SerializerFeature... features) { SerializeWriter out = new SerializeWriter(); try { JSONSerializer serializer = new JSONSerializer(out); for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) { serializer.config(feature, true); } serializer.write(object); return out.toBytes("UTF-8"); } finally { out.close(); } }