全局:简化 file 组件,融合到 infra 模块

This commit is contained in:
YunaiV
2024-02-28 18:59:33 +08:00
parent 067ff6cc4d
commit 77d634038c
48 changed files with 300 additions and 367 deletions

View File

@ -136,6 +136,21 @@ public class JsonUtils {
}
}
/**
* 解析 JSON 字符串成指定类型的对象,如果解析失败,则返回 null
*
* @param text 字符串
* @param typeReference 类型引用
* @return 指定类型的对象
*/
public static <T> T parseObjectQuietly(String text, TypeReference<T> typeReference) {
try {
return objectMapper.readValue(text, typeReference);
} catch (IOException e) {
return null;
}
}
public static <T> List<T> parseArray(String text, Class<T> clazz) {
if (StrUtil.isEmpty(text)) {
return new ArrayList<>();