|
|
@@ -4,7 +4,9 @@ import cc.smtweb.framework.core.common.SwMap; |
|
|
|
import cc.smtweb.framework.core.exception.JsonParseException; |
|
|
|
import cc.smtweb.framework.core.util.jackson.*; |
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude; |
|
|
|
import com.fasterxml.jackson.core.JsonFactory; |
|
|
|
import com.fasterxml.jackson.core.JsonGenerator; |
|
|
|
import com.fasterxml.jackson.core.JsonParser; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
|
|
|
import com.fasterxml.jackson.databind.JavaType; |
|
|
@@ -101,6 +103,7 @@ public class JsonUtil { |
|
|
|
|
|
|
|
public static <T> T parse(String str, Class<T> clazz) { |
|
|
|
try { |
|
|
|
|
|
|
|
if (StringUtils.isBlank(str)) { |
|
|
|
return null; |
|
|
|
} else { |
|
|
@@ -112,6 +115,31 @@ public class JsonUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 解析指定json节点 |
|
|
|
* @param str 完整json串 |
|
|
|
* @param nodePath 待解析节点路径,如a.b.c |
|
|
|
* @param clazz |
|
|
|
* @return |
|
|
|
* @param <T> |
|
|
|
*/ |
|
|
|
public static <T> T parse(String str, String nodePath, Class<T> clazz) { |
|
|
|
try { |
|
|
|
if (StringUtils.isBlank(str)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
JsonNode node = OBJECT_MAPPER.readTree(str); |
|
|
|
String[] nodes = nodePath.split("\\."); |
|
|
|
for (String s: nodes) { |
|
|
|
node = node.get(s); |
|
|
|
if (node == null) return null; |
|
|
|
} |
|
|
|
return OBJECT_MAPPER.treeToValue(node, clazz); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new JsonParseException("can't convert this json to " + clazz + " type", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将Map对象转换为Bean对象 |
|
|
|
* |
|
|
|
* @param map Map对象 |
|
|
|