0
我有這樣的JSON:傑克遜JSON API反序列化流無法識別的現場
[{"cdCondicaoPagto":"1","NrParcela":1,"NrDias":0}]
這個類:
public static class CondicaoPagtoItem implements Serializable {
private String cdCondicaoPagto;
private Integer NrParcela;
private Integer NrDias;
public CondicaoPagtoItem() {
}
public String getCdCondicaoPagto() {
return cdCondicaoPagto;
}
public void setCdCondicaoPagto(String cdCondicaoPagto) {
this.cdCondicaoPagto = cdCondicaoPagto;
}
public Integer getNrParcela() {
return NrParcela;
}
public void setNrParcela(Integer NrParcela) {
this.NrParcela = NrParcela;
}
public Integer getNrDias() {
return NrDias;
}
public void setNrDias(Integer NrDias) {
this.NrDias = NrDias;
}
}
而且我想通過流來讀它,這樣說:
JsonFactory jsonFactory = new JsonFactory();
ObjectMapper jsonMapper = new ObjectMapper(jsonFactory);
JsonNode jsonNodeGeral = jsonMapper.readTree(new File("/home/cechinel/Documentos/CondicaoPagtoItem.json"));
Iterator<JsonNode> elements = jsonNodeGeral.getElements();
while(elements.hasNext()){
JsonNode jsonNode = elements.next();
CondicaoPagtoItem condicao = jsonMapper.treeToValue(jsonNode, CondicaoPagtoItem.class);
}
但它會導致以下錯誤:
UnrecognizedPropertyException: Unrecognized field "NrParcela"
如果我使用註釋@JsonProperty它的作品,但我不想在哪個整數字段。
Omg。我不相信我沒有看到那個kkk。謝謝。它起作用^^ – Cechinel