title: How to send json with multipart file in Spring?
body: <p>I've stumbled across similar questions and have understood that @RequestBody cannot be sent with a multipart file in Spring. Can anyone explain why is that?</p>
  
  <p>Some suggested using @RequestPart for both data and file and I embraced it. 
  My controller is as follows:</p>
  
  <pre><code>@PostMapping(value = "localhost:8080/medicine", consumes = {"multipart/form-data"})
  @ResponseBody
  public BooleanResponse saveMedicineData(@RequestPart(value = "file") MultipartFile file, @RequestPart Medicine medicine) {
  ...
  }
  </code></pre>
  
  <p>Medicine is a entity class with Lombok annotations. Its implemented as follows:</p>
  
  <pre><code>@Data
  @Table(name = "medicine")
  @Entity
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  public class Medicine {
  
  private Long id;
  
  private String name;
  
  private String url;
  }
  </code></pre>
  
  <p>Upon making a post request to this url on postman I get this exception:</p>
  
  <pre><code>{
      "timestamp": 1533476503168,
       "status": 415,
       "error": "Unsupported Media Type",
      "exception": 
      "org.springframework.web.HttpMediaTypeNotSupportedException",
       "message": "Content type 'application/octet-stream' not supported",
       "path": "/medicine"
  </code></pre>
  
  <p>}</p>
  
  <p>How do I deal with this error?</p>