私はこのjsonファイルを持っています
[
{
"foo":{
"comment":null,
"media_title":"How I Met Your Mother",
"user_username":"nani"
}
},
{
"foo":{
"comment":null,
"media_title":"Family Guy",
"user_username":"nani"
}
}
]
つまり、これは Foo エンティティの配列です。
次に、Foo オブジェクトを取得しました。
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
@JsonRootName("foo")
public class Foo {
@JsonProperty
String comment;
@JsonProperty("media_title")
String mediaTitle;
@JsonProperty("user_username")
String userName;
/** setters and getters go here **/
}
次に、次のように FooTemplate を取得しました。
public List<Foo> getFoos() {
return java.util.Arrays.asList(restTemplate.getForObject(buildUri("/foos.json"),
Foo[].class));
}
しかし、簡単なテストを実行すると、次のようになります。
org.springframework.web.client.ResourceAccessException: I/O error: Unrecognized field "foo" (Class org.my.package.impl.Foo), not marked as ignorable at [Source: java.io.ByteArrayInputStream@554d7745; line: 3, column: 14] (through reference chain: org.my.package.impl.Foo["foo"]);