有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将响应头解析为自定义POJO

调用API

我现在创建了一个POJO来映射Json响应

@JsonInclude(JsonInclude.Include.NON_NULL)
JsonIgnoreProperties(ignoreUnknown = true)
public  class ResponseBricks<T>{

public ResponseBricks<T>(@JsonProperty("location") Location location,
        @JsonProperty("properties") Properties properties, 
         @JsonProperty("error") AzureError error) {

    this.location = location;
    this.properties = properties;
    this.error = error;
}

public Location getLocation() {
    return location;
}

public void setLocation(Location  location) {
    this.location = location;
}

public T getProperties() {
    return properties;
}

public void setProperties(T properties) {
    this.properties = properties;
}

public AzureError getError() {
    return error;
}

public void setErrorAzureError error) {
    this.error = error;
}

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}



public Response getResponse() {
    return response;
}

public void setResponse(Response response) {
    this.response = response;
}



private Location location;
private T properties;
private String id;
private String name;
private AzureError error;
private Response response;

}

现在我需要来自响应的标题,因此包括

private Response response;

但是,响应没有精确映射到azure调用的响应,并且响应为null。 如果将响应保留为响应而不是自定义POJO,则可以获取标题。但是,有没有办法使用自定义pojo,将响应作为其中的变量


共 (1) 个答案

  1. # 1 楼答案

    所以我试过了。唯一的方法是使用响应。响应的自定义Pojo不会给出标题。 Response有很多方法,不仅可以获取头,还可以获取主体