In my spring MVC app, I'm trying to make a simple Post request but it doesn't work because of the body of my request. I got nested objects in my params and Spring throws this exception :
org.springframework.beans.InvalidPropertyException: Invalid property 'contrats[0][nomFichier]' of bean class [fr.mnh.signweb.dto.InitSignatureRQDTO]: Property referenced in indexed property path 'contrats[0][nomFichier]' is neither an array nor a List nor a Map; returned value was [fr.mnh.signweb.dto.ContratDTO@1c74fdf]
Here is the json sent to the request : (I didn't show the values)
And here is my object DTO :
@NoArgsConstructor
public class InitSignatureRQDTO {
@Getter
@Setter
private String referenceFournisseur;
@Getter
@Setter
private String produit;
@Getter
@Setter
private String civilite;
@Getter
@Setter
private String nom;
@Getter
@Setter
private String prenom;
@Getter
@Setter
private String email;
@Getter
@Setter
private String telephone;
@Getter
@Setter
private String rue;
@Getter
@Setter
private String complementRue;
@Getter
@Setter
private String codePostal;
@Getter
@Setter
private String ville;
@Getter
@Setter
private String pays;
@Getter
@Setter
private List<ContratDTO> contrats;
@Getter
@Setter
private String messageSms;
}
And :
@NoArgsConstructor
public class ContratDTO {
@Getter
@Setter
private String nomFichier;
/*@Getter
@Setter
private byte[] fichier;*/
}
Here is my controller :
@RequestMapping(value = "/initSign", method = RequestMethod.POST)
public ResponseEntity launchSign(InitSignatureRQDTO initSignatureRQDTO) {
System.out.println(initSignatureRQDTO);
}
I tried to use @RequestBody like :
public ResponseEntity launchSign(@RequestBody InitSignatureRQDTO initSignatureRQDTO)
But it doesn't work. I have the x-www-form-urlencoded;charset=UTF-8 not supported exception.
EDIT : When using :
@RequestMapping(value = "/initSign", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity launchSign(InitSignatureRQDTO initSignatureRQDTO) {
I got these logs :
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing POST request for [/initSign]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /initSign
DEBUG: org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
DEBUG: org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
DEBUG: org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request