I'm facing an issue in production, and I don't understand if it's a bug or a feature of Spring.
I tried to create the following endpoint which create a resource. It receives a file and some structured data at it follows:
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<GenericResponse> create(
@ModelAttribute @Valid RequestDto dto
)
@Getter
@Setter
public class RequestDto {
MultipartFile file;
String name;
}
Important: No encoding configurations are made through app.properties The strange things happens when you try to send a request with name containing characters with accents (ex: Romanian ones ăâț). For example Ă is decoded to Ä.
I don't want explicitly a solution but rather the logic behind @ModelAttribute
, because switching to @RequestBody
works fine with any type of character. Why these 2 are using different deserialisers or configurations ?
Comment From: snicoll
It's hard to give you support with partial code snippet like that. Perhaps you need to configure CharacterEncodingFilter
? There are several questions on StackOverflow that deals with this.