add method

This commit is contained in:
Looly 2020-05-05 13:25:17 +08:00
parent c00ab6e126
commit 4aee10da40

View File

@ -331,6 +331,18 @@ public final class JSONUtil {
return json.toJSONString(0);
}
/**
* 转为JSON字符串并写出到write
*
* @param json JSON
* @since 5.3.3
*/
public static void toJsonStr(JSON json, Writer writer) {
if (null != json) {
json.write(writer);
}
}
/**
* 转为JSON字符串
*
@ -354,12 +366,25 @@ public final class JSONUtil {
if (null == obj) {
return null;
}
if (obj instanceof String) {
return (String) obj;
if (obj instanceof CharSequence) {
return StrUtil.str((CharSequence) obj);
}
return toJsonStr(parse(obj));
}
/**
* 转换为JSON字符串并写出到writer
*
* @param obj 被转为JSON的对象
* @param writer Writer
* @since 5.3.3
*/
public static void toJsonStr(Object obj, Writer writer) {
if (null != obj) {
toJsonStr(parse(obj), writer);
}
}
/**
* 转换为格式化后的JSON字符串
*