|
@@ -47,6 +47,21 @@ public class JsonHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static <T> T toObj(byte[] bytes, Class<T> clazz) {
|
|
|
|
+ if (bytes.length == 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
+ mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
|
|
|
+ return mapper.readValue(bytes, clazz);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("JSON:{} ERR:{}", new String(bytes), e.getMessage());
|
|
|
|
+ throw new StatusException("JSON解析失败!", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static <T> List<T> toList(String jsonStr, Class<T> clazz) {
|
|
public static <T> List<T> toList(String jsonStr, Class<T> clazz) {
|
|
if (StringUtils.isEmpty(jsonStr)) {
|
|
if (StringUtils.isEmpty(jsonStr)) {
|
|
return null;
|
|
return null;
|