首页 金刚区 标签 详情 标签VO一堆

This commit is contained in:
2024-04-11 14:26:35 +08:00
parent 1b9d069bc6
commit 9a6f6eb5b6
21 changed files with 592 additions and 633 deletions

View File

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
@@ -172,6 +173,25 @@ public class JSONUtil {
}
}
/**
* @param list 某集合
* @param clazz 要转成的实体
* @return
* @param <T>
*/
public static <T> List<T> parseListTNewList(List<?> list, Class<T> clazz) {
ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器
try {
// 将List<?>转换为JSON字符串
String json = objectMapper.writeValueAsString(list);
// 将JSON字符串转换为List<T>
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static class JSONEntity {
public JSONEntity() {
}