2
我遵循教程http://spring.io/guides/gs/consuming-rest/消耗休息服務。本教程僅提到了單層JSON文件。但是我想分析JSON像與嵌套json彈簧消費休息
Foo: {
fooz: 'stringdescripoers}
bar : {
baz: "something",
etc: [[1,2],[2,0]]
},
{another object like bar},
{etc}
}
根據TOT與Maven的turtorial我有以下主要類
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
public class Application {
public static void main(String args[]) {
RestTemplate restTemplate = new RestTemplate();
FeatureCollection collection = restTemplate.getForObject("http://www.trafficlink-online.nl/trafficlinkdata/wegdata/TrajectSensorsNH.GeoJSON", FeatureCollection.class);
System.out.println("it worked");
}
}
和我的課看起來像這樣已經成立了該項目。
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class FeatureCollection {
private String type;
public String getType() {
return type;
}
}
當我通過彈簧引導運行運行此我得到了我的命令行下面的結果:
tons of info,
[INFO] Attaching agents: []
14:54:02.566 [main] DEBUG o.s.web.client.RestTemplate - Created GET request for "http://www.trafficlink-online.nl/trafficlinkdata/wegdata/TrajectSensorsNH.GeoJSON"
14:54:02.634 [main] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json]
14:54:02.719 [main] DEBUG o.s.web.client.RestTemplate - GET request for "http://www.trafficlink-online.nl/trafficlinkdata/wegdata/TrajectSensorsNH.GeoJSON" resulted in 200 (OK)
Exception in thread "main" org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class FeatureCollection] and content type [text/plain;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:108)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:795)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:779)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:559)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:512)
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:268)
at Application.main(Application.java:13)
有什麼事,我沒有看到?