JsonMappingException: Kann nicht bauen Instanz CommonsMultipartFile

Ich mit Spring-MVC 3 und meine Bewerbung, ich schicke einige Informationen
mit mehreren Anhängen, und diese beiden Dateien haben einen Titel, Id, etc. Also machte ich einen DTO wie folgt

public class MyDTO {

Long id;

Integer age;

MultipartFile infoFile;

//getter setter

Ich bin nur die Schaffung eines JSON Objekt nach oben DTO-Klasse in meinem JS Datei.

Hier ist mein Controller mapping:

@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();
        }

Aber ich erhalte folgenden Fehler:

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"])
  • Sie wahrscheinlich möchte einen no-arg-Konstruktor, und CommonsMultipartFile nicht ein.
  • Konnte Sie zeigen, wie Ihre JSON aussieht?
InformationsquelleAutor Avinash | 2014-07-08
Schreibe einen Kommentar