即时使用以下代码
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
WebTarget webTarget = client.target(uri);
Builder builder = webTarget.request();
Response response = builder.accept(MediaType.APPLICATION_JSON).get(Response.class);
final List<MyResponse> accountList = response.readEntity(new GenericType<List<MyResponse>>(){});
这会返回accountList,但列表对象中的所有值都是** null 即(MyResponse对象中的每个属性值都为null)
但如果我使用下面的代码
String myResponse = response
.readEntity(String.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MyResponse[] obj = mapper.readValue(myResponse, MyResponse[].class);
obj返回正确的Objects数组..但我不想读为字符串并反序列化 ..请提示!
Uri的回应如下
[
{
"type": "A1",
"attrs": {
"test_card": "Y"
}
}, {
"type": "A2"
"attrs": {
"issue_card": "N"
}
}
]
MyResponse对象
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyResponse implements Serializable {
@JsonProperty("type")
private String Type;
@JsonProperty("attrs")
private MyAttributes myAttributes;
public MyAttributes getattrs() {
return myAttributes;
}
public void setattrs(MyAttributes myAttributes) {
this.myAttributes = myAttributes;
}
public MyResponse() {
}
public String gettype() {
return Type;
}
public void settype(String Type) {
this.Type = Type;
}
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
}
MyAttributes Object
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyAttributes implements Serializable {
/**
*
*/
private static final long serialVersionUID = -4************;
@JsonProperty("test_card")
private String testCard;
public DecisionActionAttributes() {
}
public String getNewCardInd() {
return testCard;
}
public void setNewCardInd(String testCard) {
this.testCard = testCard;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this, false);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}