@JsonCreator
public Foo( @JsonProperty("title") String title,
@JsonProperty("strTags") Collection<String> strTags) {
this.title = title;
this.strTags = strTags;
}
メソッドsigは次のようになります。
@RequestMapping(value = "/Preview", method = RequestMethod.POST)
public ModelAndView preview(@RequestBody final Foo foo) {..}
そして、テストは次のとおりです。
String json = "\"foo\":{\"title\":\"test\",\"strTags\":[\"Tag1\",\"tag2\"]}";
MvcResult mvcResult = this.mockMvc.perform(
post("/Preview/").contentType(MediaType.APPLICATION_JSON).content(json))
.andExpect(status().isOk())
.andExpect(model().attributeExists("foo"))
.andExpect(view().name("foo/preview"))
.andDo(print())
.andReturn();
}
ただし、次のエラーが発生します。
no suitable creator method found to deserialize from JSON String