diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/JsonUtil.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/JsonUtil.java index 56da985a..575dd56d 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/JsonUtil.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/JsonUtil.java @@ -88,15 +88,11 @@ public class JsonUtil { * @param json json字符串 * @param cls 目标对象 */ - public static T toObject(String json, Class cls) { - if(StringUtils.isBlank(json) || cls == null){ + public static T toObject(JsonNode json, Class cls) { + if(json == null || cls == null){ return null; } - try { - return MAPPER.readValue(json, cls); - } catch (IOException e) { - throw new RuntimeException(e); - } + return MAPPER.convertValue(json, cls); } /** @@ -134,6 +130,22 @@ public class JsonUtil { } } + /** + * 字符串转换为指定对象 + * @param json json字符串 + * @param cls 目标对象 + */ + public static T toObject(String json, Class cls) { + if(StringUtils.isBlank(json) || cls == null){ + return null; + } + try { + return MAPPER.readValue(json, cls); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + /** * 字符串转换为JsonNode对象 * @param json json字符串