【发布时间】:2014-09-27 08:40:27
【问题描述】:
我有一个 REST 服务已经在运行,它返回下面的示例 JSON:
{
"_embedded" : {
"artist" : [ {
"name" : "+44",
"genre" : "Rock",
"country" : "USA",
"id" : 469,
"_links" : {
"self" : {
"href" : <ADDRESS>
},
"albumList" : {
"href" : <ADDRESS>
}
}
} ]
}
}
我正在尝试使用 RestTemplate 使用此资源,如下例所示
public static void main(String args[]) {
RestTemplate restTemplate = new RestTemplate();
Artist[] artistList = restTemplate.getForObject("http://localhost:8080/artists/search/findByName?name=+44", Artist[].class);
for (Artist a : artistList)
System.out.println(a.toString());
}
}
当调试器点击 getForObject 行时,它得到这个错误:
Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException:
Could not read JSON: Can not deserialize instance of br.com.lagranzotto.itunes.frontend.entity.Artist[] out of START_OBJECT token
我已经在互联网上广泛搜索了大约一个星期,但没有成功找到此异常的原因。
【问题讨论】: