前提・実現したいこと
外部APIからSpringを使用しJSON形式のデータを取得するシステムを作っています。
RestTemplateを使用し情報を取得する処理を実装中に以下のエラーメッセージが発生しました。
データの取得を行うにはどのようにすれば良いのでしょうか。
発生している問題・エラーメッセージ
Exception in thread "main" org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class apinotest.getcity.Result] and content type [application/json;charset=utf-8] at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:119) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:725) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:332) at apinotest.getcity.GetCity.main(GetCity.java:11)
該当のソースコード
GetCity
1package apinotest.getcity; 2 3import org.springframework.web.client.RestTemplate; 4 5public class GetCity { 6 public static void main(String[] args) { 7 RestTemplate restTemplate = new RestTemplate(); 8 Result result = restTemplate.getForObject("http://www.land.mlit.go.jp/webland/api/CitySearch?area=13",Result.class); 9 } 10}
Result
1package apinotest.getcity; 2 3import java.util.List; 4 5public class Result { 6 private String status; 7 private List<City> data; 8 9 public String getStatus() { 10 return status; 11 } 12 13 public void setStatus(String status) { 14 this.status = status; 15 } 16 17 public List<City> getData() { 18 return data; 19 } 20 21 public void setData(List<City> data) { 22 this.data = data; 23 } 24} 25
City
1package apinotest.getcity; 2 3public class City { 4 private String id; 5 private String name; 6 7 public String getId() { 8 return id; 9 } 10 11 public void setId(String id) { 12 this.id = id; 13 } 14 15 public String getName() { 16 return name; 17 } 18 19 public void setName(String name) { 20 this.name = name; 21 } 22}
補足情報(FW/ツールのバージョンなど)
取得するAPI
http://www.land.mlit.go.jp/webland/api.html#todofukenlist
jara:1.8

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。