我的 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 来返回数组或列表,但不能嵌套在数据对象中。