restTemplate.getForObject
Rsp<ShopNewInfo> rsp = restTemplate.getForObject(url+"&shopId="+Shop.getShopId(), Rsp.class);
用getForObject方法,用泛型接收,报错:信息如下:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.*.biz.mds.dto..ShopNewInfo
getForObject 返回的是LinkedHashMap
restTemplate.exchange 支持泛型
ParameterizedTypeReference<Rsp<ShopNewInfo>> reference = new ParameterizedTypeReference<Rsp<ShopNewInfo> >() {};
ResponseEntity<Rsp<ShopNewInfo>> entity = restTemplate.exchange(reqUrl, HttpMethod.GET,null,reference);
Rsp<ShopNewInfo> rsp = entity.getBody();
public class ZhiyiRsp<T> {
private T result;
private boolean success;
}
public class ZhiyiShopNewInfo {
private Integer id;
@JsonProperty("shop_id")
private Long shopId;
}