[英]Jackson object mapper not creating proper Json string from java object
[英]deserialise the list of integer from json to java using Jackson Object Mapper
我的 json 响应如下:
{"IsValid":false,"ModelErrors":null,"ValidationErrors":[10000]}
模型类:
public class ShipmentResponse {
private boolean isValid;
private ModelErrors modelErrors;
private List<Integer> validationErrors = null;
对象映射器代码:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ShipmentResponse shipmentResponse = mapper.readValue((BufferedInputStream)response.getEntity(), ShipmentResponse.class);
我无法将validationErrors从json 映射到java,即validationErrors = null 解析后。我期待validationErrors = {1000} 但不知道为什么? 我知道我们可以使用 TypeReference 来返回数组或列表,但不能嵌套在数据对象中。
尝试这个
public class ShipmentResponse {
@JsonProperty("IsValid")
private boolean isValid;
@JsonProperty("ModelErrors")
private ModelErrors modelErrors;
@JsonProperty("ValidationErrors")
private List<Integer> validationErrors = null;
}
通常,您的属性名称和实际 json 不匹配(大小写很重要)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.