ソースを参照

添加 toJson(Object object, SerializerFeature...
features),支持指定SerializerFeature生成 json

James 3 年 前
コミット
d50bd224da
1 ファイル変更15 行追加0 行削除
  1. 15 0
      src/main/java/com/jfinal/json/FastJson.java

+ 15 - 0
src/main/java/com/jfinal/json/FastJson.java

@@ -56,6 +56,21 @@ public class FastJson extends Json {
 		}
 	}
 	
+	/**
+	 * 支持传入更多 SerializerFeature
+	 * 
+	 * 例如:
+	 *    SerializerFeature.WriteMapNullValue 支持对 null 值字段的转换
+	 */
+	public String toJson(Object object, SerializerFeature... features) {
+		String dp = datePattern != null ? datePattern : getDefaultDatePattern();
+		if (dp == null) {
+			return JSON.toJSONString(object);
+		} else {
+			return JSON.toJSONStringWithDateFormat(object, dp, features);
+		}
+	}
+	
 	public <T> T parse(String jsonString, Class<T> type) {
 		return JSON.parseObject(jsonString, type);
 	}