json 实体类转换
// decryptData json格式
JSONObject dataJson = JSONObject.parseObject(decryptData);
// 转form表单 MeituanOrderQueryForm实体类
MeituanOrderQueryForm form = JSON.toJavaObject(dataJson, MeituanOrderQueryForm.class);
json list<实体类>转换
// data json
String data = (String) redisUtil.get(key);
if (!Objects.isNull(data)) {
JSONArray jsonArray = JSONArray.parseArray(data);
List<CssHotelRuleQuantity> numRuleList = jsonArray.toJavaList(CssHotelRuleQuantity.class);
// 优先级排序
numRuleList = numRuleList.stream().sorted(Comparator.comparingInt(CssHotelRuleQuantity::getRuleLevel).reversed()).collect(Collectors.toList());
}
参考:
https://blog.csdn.net/wkw1598727534/article/details/107104361/