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

时间:2019-03-08 10:50:06

标签: java azure jax-rs

调用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 个答案:

答案 0 :(得分:0)

所以尝试了这一点。唯一的方法是使用Response.Custom Pojo进行响应不会给出标题。 响应有很多方法不仅可以获取标头,还可以获取正文。