refer:https://blog.youkuaiyun.com/qq_28807077/article/details/111049345
反序列化时,对泛型的反序列化,不能写成如下的方式,会报错:
String userString = "[{\"userId\":\"111\",\"userName\":\"Tom\"},{\"userId\":\"222\",\"userName\":\"Jerry\"}]";
List<UserInfo> input = new ArrayList<>();
List<UserInfo> userInfoList = JSON.parseObject(userString, input.getClass());
需要使用fastjson提供的 TypeReference类
,它用于处理反序列化的类型是泛型类型
List<UserInfo> userInfoList = JSON.parseObject(userString, new TypeReference<List<UserInfo>>() {});
Assert
org.springframework.util
包中提供的Assert
可用于判断且会自动抛出异常。
Assert.notNull(payload, "payload must not be null");