I know how to create endpoints that process files using MediaType.MULTIPART_FORM_DATA and @FormDataParam("file") FormDataBodyPart bodyPart , but I was wondering if I can also have JSON data for this request? Something like:
@POST @Path("somepath") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFileAndJSON(@RequestBody SomeModel someModel, @FormDataParam("file") FormDataBodyPart bodyPart) { return null; }
For now, if I add some JSON data to the "raw" tab in the next Postman request, I get an HTTP 415 Unsupported Media Type , probably because I indicated that I am using MULTIPART_FORM_DATA , but I also use @RequestBody , which is looking for JSON content that is APPLICATION_JSON . So, how can I get the JSON data and the file being processed in the same request? I know that it is possible to do this in two queries, I just want to do this in one, if possible?

java json spring rest multipartform-data
Anton Belev
source share