无法读取JSON:无法识别的字段" geo:point"与jsonschema2pojo-maven-plugin

时间:2013-07-30 11:20:26

标签: java json

您在尝试从我的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),未标记为可忽略    在[来源:sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687; line:1,column:191](通过参考链:imis.athena.client.lastfm.dto.LastFMEventsDTO [" events"] - > imis.athena.client.lastfm.dto.Events [& #34;事件"] - > imis.athena.client.lastfm.dto.Event ["场地"] - > imis.athena.client.lastfm.dto.Venue [&#34 ;位置"] - > imis.athena.client.lastfm.dto.Location ["地理:点"]);嵌套异常是org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段" geo:point" (类imis.athena.client.lastfm.dto.Location),未标记为可忽略    在[来源:sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687; line:1,column:191](通过参考链:imis.athena.client.lastfm.dto.LastFMEventsDTO [" events"] - > imis.athena.client.lastfm.dto.Events [& #34;事件"] - > imis.athena.client.lastfm.dto.Event ["场地"] - > imis.athena.client.lastfm.dto.Venue [&#34 ;位置"] - > imis.athena.client.lastfm.dto.Location ["地理:点"])       在org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readJavaType(MappingJacksonHttpMessageConverter.java:170)       在org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.read(MappingJacksonHttpMessageConverter.java:162)       在org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:94)       在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:492)       在org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447)       在org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:215)       at imis.athena.client.lastfm.run.LastFMRunner.initiateApiRequests(LastFMRunner.java:53)       at 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),未标记为可忽略    在[来源:sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6391b687; line:1,column:191](通过参考链:imis.athena.client.lastfm.dto.LastFMEventsDTO [" events"] - > imis.athena.client.lastfm.dto.Events [& #34;事件"] - > imis.athena.client.lastfm.dto.Event ["场地"] - > imis.athena.client.lastfm.dto.Venue [&#34 ;位置"] - > imis.athena.client.lastfm.dto.Location ["地理:点"])       at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)       at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)       at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)       at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)       at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)       在org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)       at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)       在org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)       at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)       at org.codehaus.jackson.map.deser.SettableBeanProperty $ MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)       at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)       在org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)       at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)       at org.codehaus.jackson.map.deser.SettableBeanProperty $ MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)       at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)       在org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)       在org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)       at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)       at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)       at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)       at org.codehaus.jackson.map.deser.SettableBeanProperty $ MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)       at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)       在org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)       at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)       at org.codehaus.jackson.map.deser.SettableBeanProperty $ MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)       at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)       在org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)       at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)       at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1923)       在org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readJavaType(MappingJacksonHttpMessageConverter.java:167)       ......还有8个

编辑有问题的java类

  

@JsonInclude(JsonInclude.Include.NON_NULL)   @Generated(" com.googlecode.jsonschema2pojo&#34)   @JsonPropertyOrder({       "城市&#34 ;,       "国家&#34 ;,       "地理:点&#34 ;,       "邮编&#34 ;,       "街道"   })

     

公共课位置{

/**
 * 
 */
@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);
}

}

0 个答案:

没有答案