0
をPOJOに取り組んでいない私はJSON
を取得しています:春を使用してAndroidアプリでのWeb APIから春Androidのマッピングは
[{"LocationId":1,"LocationCode":"Area A"},{"LocationId":2,"LocationCode":"Area B"}]
が、そのは、POJOにマップするために失敗:
@JsonIgnoreProperties(ignoreUnknown = true)
public class DataLocation {
private String LocationId;
private String LocationCode;
public String getLocationId(){
return LocationId;
}
public String getLocationCode(){
return LocationCode;
}
}
これは、 json
を取得するコード:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<DataLocation[]> forNow = restTemplate.getForEntity(url, DataLocation[].class);
地図作成に失敗した理由は誰でも知っていますか?
EDIT
このlinkはspring
経由json
に変換することができpojo
を作成するために助けました。だから、結果POJO
は、次のようになります。
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"LocationId",
"LocationCode"
})
public class DataLocation {
@JsonProperty("LocationId")
private Integer locationId;
@JsonProperty("LocationCode")
private String locationCode;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("LocationId")
public Integer getLocationId() {
return locationId;
}
@JsonProperty("LocationId")
public void setLocationId(Integer locationId) {
this.locationId = locationId;
}
@JsonProperty("LocationCode")
public String getLocationCode() {
return locationCode;
}
@JsonProperty("LocationCode")
public void setLocationCode(String locationCode) {
this.locationCode = locationCode;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
など、あなたがセッターに奇数値を変換する必要がある場合は特に、非常に便利なツールであることはできません?奇数の場合については
私は1つを生成することができました[ここ](http://jsonschema2pojo.org) –
GSONはjsonをPOJOに解析する方が良いです。 – Kintanpatel
私は 'List'を得て、それを 'List ' –
JustLearning