@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