1

嗨,我在尝试从我的 java 客户端应用程序调用 lastFM API 时遇到以下异常。我使用了 jsonschema2pojo-maven-plugin 来自动生成我的类。我需要 lat 和 long 字段(我不想忽略它们) 我试图读取的 json 如下:LastFM API Call。有任何想法吗?

location: {geo:point: {geo:lat: "51.539739",geo:long: "-0.102676"}

线程“main”org.springframework.http.converter.HttpMessageNotReadableException 中的异常:无法读取 JSON:无法识别的字段“geo:point”(类 imis.athena.client.lastfm.dto.Location),在 [Source] 中未标记为可忽略: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687; 行:1,列:191](通过引用链:imis.athena.client.lastfm.dto.LastFMEventsDTO["events"]->imis.athena.client.lastfm.dto.Events["event"]->imis .athena.client.lastfm.dto.Event["venue"]->imis.athena.client.lastfm.dto.Venue["location"]->imis.athena.client.lastfm.dto.Location["geo:观点”]); 嵌套异常是 org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "geo:point" (类 imis.athena.client.lastfm.dto.Location),在 [来源:sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687;未标记为可忽略;行:1,列:191](通过引用链:imis.athena.client.lastfm.dto.LastFMEventsDTO["events"]->imis.athena.client.lastfm.dto.Events["event"]->imis .athena.client.lastfm.dto.Event["venue"]->imis.athena.client.lastfm.dto.Venue["location"]->imis.athena.client.lastfm.dto.Location["geo:点"]) 在 org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.read(MappingJacksonHttpMessageConverter.java:162) 在 org.springframework 的 org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readJavaType(MappingJacksonHttpMessageConverter.java:170) .web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor. java:94) 在 org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447) 在 org.springframework.web.client 的 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:492) .RestTemplate.getForObject(RestTemplate.java:215) 在 imis.athena.client.lastfm.run.LastFMRunner.initiateApiRequests(LastFMRunner.java:53) 在 imis.athena.client.lastfm.run.LastFMRunner.initiateSpringContextAndRun(LastFMRunner.java :45) at imis.athena.client.lastfm.run.LastFMRunner.main(LastFMRunner.java:39) 原因:org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段“geo:point”(imis 类。 athena.client.lastfm.dto.Location),在 [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687; 行:1,列:

编辑有问题的java类

@JsonInclude(JsonInclude.Include.NON_NULL) @Generated("com.googlecode.jsonschema2pojo") @JsonPropertyOrder({ "city", "country", "geo:point", "postalcode", "street" })

公共类位置{

/**
 * 
 */
@JsonProperty("city")
private String city;
/**
 * 
 */
@JsonProperty("country")
private String country;
/**
 * 
 */
@JsonProperty("geo:point")
private Geo_point geo_point;
/**
 * 
 */
@JsonProperty("postalcode")
private String postalcode;
/**
 * 
 */
@JsonProperty("street")
private String street;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
 * 
 */
@JsonProperty("city")
public String getCity() {
    return city;
}

/**
 * 
 */
@JsonProperty("city")
public void setCity(String city) {
    this.city = city;
}

/**
 * 
 */
@JsonProperty("country")
public String getCountry() {
    return country;
}

/**
 * 
 */
@JsonProperty("country")
public void setCountry(String country) {
    this.country = country;
}

/**
 * 
 */
@JsonProperty("geo:point")
public Geo_point getGeo_point() {
    return geo_point;
}

/**
 * 
 */
@JsonProperty("geo:point")
public void setGeo_point(Geo_point geo_point) {
    this.geo_point = geo_point;
}

/**
 * 
 */
@JsonProperty("postalcode")
public String getPostalcode() {
    return postalcode;
}

/**
 * 
 */
@JsonProperty("postalcode")
public void setPostalcode(String postalcode) {
    this.postalcode = postalcode;
}

/**
 * 
 */
@JsonProperty("street")
public String getStreet() {
    return street;
}

/**
 * 
 */
@JsonProperty("street")
public void setStreet(String street) {
    this.street = street;
}

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this);
}

@Override
public int hashCode() {
    return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object other) {
    return EqualsBuilder.reflectionEquals(this, other);
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
    return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperties(String name, Object value) {
    this.additionalProperties.put(name, value);
}

}

4

0 回答 0