resttemplate consume api error
<p>I am using resttemplate to consume a rest api, but I got some error:</p>

<pre><code>Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class org.apache.xpath.operations.String] from String value; no single-String constructor/factory method (through reference chain: com.shuohao.liu.newlifeinus.web.model.WeatherSearch["forecast"]-&gt;com.shuohao.liu.newlifeinus.web.model.WeatherForecast["simpleforecast"]-&gt;com.shuohao.liu.newlifeinus.web.model.WeatherSimpleForecast["forecastday"]-&gt;com.shuohao.liu.newlifeinus.web.model.WeatherForecastday["date"]-&gt;com.shuohao.liu.newlifeinus.web.model.WeatherDate["pretty"])
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createFromStringFallbacks(StdValueInstantiator.java:428)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:299)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1056)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:136)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:123)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:230)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:207)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2094)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:221)
... 86 more
</code></pre>

<p>Here is how I use the resttemplate:</p>

<pre><code>@Service

public class WeatherService {

public WeatherSearch getWeatherForecast(String city, String state, String country) {

    RestTemplate template = new RestTemplate();
    String url = "http://api.wunderground.com/api/252ab947c92cb32e/forecast10day/q/{state}/{city}.json";
    Map&lt;String, String&gt; var = new HashMap&lt;String, String&gt;();
    var.put("state", state);
    var.put("city", city);

    WeatherSearch search = new WeatherSearch();
    try {
        search = template.getForObject(url, WeatherSearch.class, var);
    }catch(ResourceAccessException ex){

        ex.printStackTrace();
        System.out.println(ex.getClass());
    }catch (Exception ex) {
        ex.printStackTrace();
        System.out.println(ex.getClass());


    }
    return search;
}
}
</code></pre>

<p>The json string is too long, it can be access from <a href="http://api.wunderground.com/api/252ab947c92cb32e/forecast10day/q/CO/denver.json" rel="nofollow">http://api.wunderground.com/api/252ab947c92cb32e/forecast10day/q/CO/denver.json</a></p>

<p>Finally, here is the object I create for such json structure:</p>

<pre><code>@JsonIgnoreProperties(ignoreUnknown=true)
public class WeatherSearch {

@JsonProperty(value="forecast")
private WeatherForecast forecast;

}


    @JsonIgnoreProperties(ignoreUnknown=true)
public class WeatherForecast {

    @JsonProperty(value="simpleforecast")
    private WeatherSimpleForecast simpleForecast;



}

    @JsonIgnoreProperties(ignoreUnknown=true)
public class WeatherSimpleForecast {

@JsonProperty(value="forecastday")
private ArrayList&lt;WeatherForecastday&gt; forecastday;

}

    @JsonIgnoreProperties(ignoreUnknown=true)
public class WeatherForecastday {

@JsonProperty(value="period")
private String period;

@JsonProperty(value="high")
private WeatherTemperature high;

@JsonProperty(value="low")
private WeatherTemperature low;

@JsonProperty(value="condition")
private String condition;

@JsonProperty(value="icon_url")
private String iconUrl;

@JsonProperty(value="date")
private WeatherDate date;
}



 @JsonIgnoreProperties(ignoreUnknown=true)
public class WeatherDate {

@JsonProperty(value="pretty")
private String pretty;
@JsonProperty(value="day")
private String day;
@JsonProperty(value="month")
private String month;
@JsonProperty(value="year")
private String year;
@JsonProperty(value="monthname")
private String monthName;
@JsonProperty(value="monthname_short")
private String monthShortName;
@JsonProperty(value="weekday")
private String weekday;
@JsonProperty(value="weekday_short")
private String weekdayShort;


}
</code></pre>