I want call controller method with Multipart file and json as parameters for it.
Here is code how I've called with JSON only(successfully):
@CrossOrigin
@RequestMapping(
value = "/login",
method = POST,
produces = APPLICATION_JSON_VALUE,
consumes = {APPLICATION_JSON_VALUE}
)
public JsonUser login(@RequestBody LoginRequest loginRequest,
BindingResult bindingResult,
HttpServletResponse response,
HttpServletRequest request) throws Exception {
///CODE HERE
return JsonUser.from(userContext);
}
Here is LoginRequest is class-model for my json request:
@JsonIgnoreProperties(ignoreUnknown = true)
public class LoginRequest {
private String email;
private String password;
public String getEmail() {
return email;
}
public String getPassword() {
return password;
}
}
Now I want make request with Image and json above in one REST controller's method. My code:
@RequestMapping( method = RequestMethod.POST,
value = "/create_ticket")
public JsonUser scan(@RequestParam("file") @Valid @NotBlank MultipartFile file, RegistrationRequest test) {
//CODE HERE
}
But i have no success. I can give MultipartFile if it's alone and json also. But i can't together.