diff --git a/CHANGELOG.md b/CHANGELOG.md index dd59aef8c..acf67eec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * 【core 】 BeanUtil.getProperty增加判空(issue#I488HA@Gitee) * 【core 】 OptionalBean弃用(pr#1182@Github) * 【setting】 Setting、Props持有URL改为持有Resource(pr#1182@Github) +* 【json 】 JSONUtil.toJsonStr增加重载,支持JSONConfig(issue#I48H5L@Gitee) ### 🐞Bug修复 * 【core 】 修复ListUtil.split方法越界问题(issue#I48Q0P@Gitee) diff --git a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java b/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java index 91b2215c6..3ee3dec66 100644 --- a/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java +++ b/hutool-json/src/main/java/cn/hutool/json/JSONUtil.java @@ -349,13 +349,24 @@ public class JSONUtil { * @return JSON字符串 */ public static String toJsonStr(Object obj) { + return toJsonStr(obj, (JSONConfig) null); + } + + /** + * 转换为JSON字符串 + * + * @param obj 被转为JSON的对象 + * @return JSON字符串 + * @since 5.7.12 + */ + public static String toJsonStr(Object obj, JSONConfig jsonConfig) { if (null == obj) { return null; } if (obj instanceof CharSequence) { return StrUtil.str((CharSequence) obj); } - return toJsonStr(parse(obj)); + return toJsonStr(parse(obj, jsonConfig)); } /**