數據反序列化參數TypeReference
使用jackson或者fastjson 將json字符串反序列化成對象(以fastjson為例)
TypeReference<AjaxResult<List<Person>>> typeReference = new TypeReference<AjaxResult<List<Person>>>() {};
String json = "{\"code\":200, \"success\":true, \"msg\":\"成功\",\"data\":[{\"name\":\"zhangsan\",\"address\":\"山東青島\"},{\"name\":\"lisi\",\"address\":\"山東濟寧\"}]}";
AjaxResult<List<Person>> listAjaxResult = JSONObject.parseObject(json, typeReference);
System.out.println(listAjaxResult);
restTemplate
restTemplate.exchange() 中ParameterizedTypeReference參數類似
紙上得來終覺淺,絕知此事要躬行。

浙公網安備 33010602011771號