我正在使用API并使用resttemplate.exchange对象获取响应,并且将响应映射到参数化对象。响应类中的所有变量都被映射到响应实体对象,而不是内部的Attribute类变量参数化的对象。
ResponseEntity<ArrayList<Response>> responseEntity =
restTemplate.exchange(
builder.toUriString(),
HttpMethod.GET,
new HttpEntity<>(headers),
new ParameterizedTypeReference<ArrayList<Response>>()
{});
@Getter
@Setter
public class Response {
private String number;
private String id;
private String name;
@JsonProperty("attributes")
private ArrayList<Attributes> attributes ;
}
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown=true)
public class Attributes {
private String value;
private String name;
}