提交 f203b4f4 编写于 作者: zlt2000's avatar zlt2000

Json工具增加方法

上级 efb384d8
......@@ -88,15 +88,11 @@ public class JsonUtil {
* @param json json字符串
* @param cls 目标对象
*/
public static <T> T toObject(String json, Class<T> cls) {
if(StringUtils.isBlank(json) || cls == null){
public static <T> T toObject(JsonNode json, Class<T> 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> T toObject(String json, Class<T> 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字符串
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册