1,依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.21</version>
</dependency>
2,数据
[
{
"thresholdValue": 3,
"name": "zjhz-xs-aaa-sdu-a1[188.102.17.34]",
"executeName": "Asm_Free_Pct[description=ASM存储空闲率]",
"operation": "2020-07-20 14:43:45 张岩 因 [阈值调整] 启用了该指标!",
"status": 1
},
{
"thresholdValue": 2,
"name": "sdu2a[139.110.168.61]",
"executeName": "Asm_Free_Pct[description=ASM存储空闲率]",
"operation": "2020-07-20 15:28:03 张岩 因 [阈值调整] 启用了该指标!",
"status": 1
}
]
3,java类
import cn.hutool.json.JSONUtil;
import java.util.List;
import cn.hutool.json.JSONArray;
public class JavaObjectToJavaEntity {
public static void main(String[] args) {
String strJsonArray = "[\n" +
" {\n" +
" \"thresholdValue\": 3,\n" +
" \"name\": \"zjhz-xs-aaa-sdu-a1[188.102.17.34]\",\n" +
" \"executeName\": \"Asm_Free_Pct[description=ASM存储空闲率]\",\n" +
" \"operation\": \"2020-07-20 14:43:45 张岩 因 [阈值调整] 启用了该指标!\",\n" +
" \"status\": 1\n" +
" },\n" +
" {\n" +
" \"thresholdValue\": 2,\n" +
" \"name\": \"sdu2a[139.110.168.61]\",\n" +
" \"executeName\": \"Asm_Free_Pct[description=ASM存储空闲率]\",\n" +
" \"operation\": \"2020-07-20 15:28:03 张岩 因 [阈值调整] 启用了该指标!\",\n" +
" \"status\": 1\n" +
" }\n" +
"]";
List<Object> list = JSONUtil.parseArray(strJsonArray);
JSONArray jsonArray = JSONUtil.parseArray(list);
List<WhiteListVO> listVOS = JSONUtil.toList(jsonArray, WhiteListVO.class);
for (WhiteListVO listVO : listVOS) {
System.out.println(listVO);
}
}
4,测试