【发布时间】:2014-08-28 20:22:30
【问题描述】:
我正在使用 Spring-MVC 3.0,在我的应用程序中,我发送了一些带有多个附件的信息,每个文件都有标题、ID 等。所以,我制作了一个 DTO,如下所示
public class MyDTO {
Long id;
Integer age;
MultipartFile infoFile;
// getter setter
我只是根据我的JS文件中的上述DTO类创建一个JSON对象。
这是我的Controller 映射:
@RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
public @ResponseBody String saveInfo(
@RequestParam(value = "data", required = true) String stdData,
@RequestParam(value = "fileData", required = false) MultipartFile[] files,
HttpSession session,HttpServletRequest request) {
MyDTO dto;
try {
dto = mapper.readValue(stdData, new TypeReference<MyDTO>() {});
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但我收到以下错误:
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.springframework.web.multipart.commons.CommonsMultipartFile,
problem: no suitable creator method found to deserialize from JSON String
at [Source: java.io.StringReader@19747c9; line: 1, column: 336] (through reference chain: com.avi.dto.MyDTO["hbvFile"])
【问题讨论】:
-
它可能需要一个无参数构造函数,而
CommonsMultipartFile没有。 -
您能展示一下您的
JSON的样子吗?
标签: java json spring-mvc jackson multipart