title: Spring boot swagger multipart with json content and attachment
body: <p>I've a requirement to upload any file content using Swagger-3 along with some metadata information as a JSON within a single request. Therefore I configured following into my swagger:</p>
  <pre><code>&quot;requestBody&quot;: {
            &quot;content&quot;: {
              &quot;multipart/form-data&quot;: {
                &quot;schema&quot;: {
                  &quot;type&quot;: &quot;object&quot;,
                  &quot;properties&quot;: {
                      &quot;metadata&quot;: {
                          &quot;$ref&quot;: &quot;#/components/schemas/Attachment&quot;
                      },
                      &quot;file&quot;: {
                          &quot;type&quot;: &quot;string&quot;, 
                          &quot;format&quot;:&quot;binary&quot;,
                          &quot;description&quot;: &quot;Actual File Attachment&quot;
                      }
                  }
                }
              }
            },
            &quot;description&quot;: &quot;The Attachment record / entry be created&quot;,
            &quot;required&quot;: true
   }
  </code></pre>
  <p>It translates to following when I build the controller object:</p>
  <pre><code>@ApiOperation(value = &quot;Upload attachments to a existing Ticket&quot;, nickname = &quot;uploadAttachment&quot;, notes = &quot;&quot;, response = Attachment.class, responseContainer = &quot;List&quot;, tags={ &quot;changeRequest&quot;, })
  @RequestMapping(value = &quot;/changeRequest/attachment/{id}&quot;,
          produces = { &quot;application/json&quot; }, 
          consumes = { &quot;multipart/form-data&quot; },
          method = RequestMethod.POST)
  public ResponseEntity&lt;List&lt;Attachment&gt;&gt; uploadAttachment(@ApiParam(value = &quot;Identifier of the Change Request&quot;,required=true) @PathVariable(&quot;id&quot;) String id,@ApiParam(value = &quot;Application ID invoking the call&quot; ,required=true) @RequestHeader(value=&quot;X-App-Id&quot;, required=true) String xAppId,@NotNull @ApiParam(value = &quot;To track unique transaction across multiple systems for audit trail&quot;, required = true) @Valid @RequestParam(value = &quot;X-Transaction-Id&quot;, required = true) String xTransactionId,@ApiParam(value = &quot;Authorization header&quot; ) @RequestHeader(value=&quot;authorization&quot;, required=false) String authorization,@ApiParam(value = &quot;&quot;, defaultValue=&quot;null&quot;) @RequestParam(value=&quot;metadata&quot;, required=false)  Attachment metadata, @ApiParam(value = &quot;file detail&quot;) @Valid @RequestPart(&quot;file&quot;) MultipartFile file) {
      
      ResponseEntity&lt;List&lt;Attachment&gt;&gt; responseEntity = new ResponseEntity&lt;&gt;(HttpStatus.OK);
      responseEntity.getBody().add(metadata);
      return responseEntity;
  
  }
  </code></pre>
  <p>Following is the Attachment schema definition:</p>
  <pre><code>&quot;Attachment&quot;: {
              &quot;type&quot;: &quot;object&quot;, 
              &quot;description&quot;: &quot;Attachment Metadata definition&quot;, 
              &quot;properties&quot;: {
                  &quot;description&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;A narrative text describing the content of the attachment&quot;
                  }, 
                  &quot;href&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;Reference of the attachment&quot;
                  }, 
                  &quot;id&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;Unique identifier of the attachment&quot;
                  }, 
                  &quot;mimeType&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;The mime type of the document as defined in RFC 2045 and RFC 2046 specifications.&quot;
                  }, 
                  &quot;name&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;The name of the file&quot;
                  }, 
                  &quot;path&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;The path of the attached file&quot;
                  }, 
                  &quot;size&quot;: {
                      &quot;type&quot;: &quot;integer&quot;, 
                      &quot;description&quot;: &quot;The size of the file (sizeUnit if present indicates the unit, otherwise kilobytes is the default).&quot;
                  }, 
                  &quot;sizeUnit&quot;: {
                      &quot;type&quot;: &quot;integer&quot;, 
                      &quot;description&quot;: &quot;The unit size for expressing the size of the file (MB,kB...)&quot;
                  }, 
                  &quot;url&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;Uniform Resource Locator, is a web page address (a subset of URI)&quot;
                  }, 
                  &quot;validFor&quot;: {
                      &quot;$ref&quot;: &quot;#/components/schemas/TimePeriod&quot;, 
                      &quot;description&quot;: &quot;Period of validity of the attachment&quot;
                  }, 
                  &quot;@type&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;The class type of the actual resource (for type extension).&quot;
                  }, 
                  &quot;@schemaLocation&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;A link to the schema describing a resource (for type extension).&quot;
                  }, 
                  &quot;@baseType&quot;: {
                      &quot;type&quot;: &quot;string&quot;, 
                      &quot;description&quot;: &quot;The base type for use in polymorphic collections&quot;
                  }
              }
  }
  </code></pre>
  <p>In the example above, Attachment metadata is what I am trying to pass as part of the SOAP API test. However I keep getting following error:</p>
  <pre><code>Mon Oct 12 17:06:28 IST 2020:DEBUG:&lt;&lt; &quot;{&quot;timestamp&quot;:&quot;2020-10-12T11:36:28.371Z&quot;,&quot;status&quot;:500,&quot;error&quot;:&quot;Internal Server Error&quot;,&quot;message&quot;:&quot;Failed to convert value of type 'java.lang.String' to required type 'com.bell.na.nt.change.swagger.model.Attachment'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.bell.na.nt.change.swagger.model.Attachment': no matching editors or conversion strategy found&quot;,&quot;path&quot;:&quot;/changeManagement/api/v1/changeRequest/attachment/1234&quot;}&quot;
  
  </code></pre>
  <p>Why is the string not being converted and mapped to the JSON object. Not sure I am missing anything. Following is what my json looks like.</p>
  <pre><code>{&quot;@baseType&quot;: &quot;string&quot;,     &quot;@schemaLocation&quot;: &quot;string&quot;,     &quot;@type&quot;: &quot;string&quot;,     &quot;description&quot;: &quot;string&quot;,     &quot;href&quot;: &quot;string&quot;,     &quot;id&quot;: &quot;string&quot;,     &quot;mimeType&quot;: &quot;string&quot;,     &quot;name&quot;: &quot;string&quot;,     &quot;path&quot;: &quot;string&quot;,     &quot;size&quot;: 0,     &quot;sizeUnit&quot;: 0,     &quot;url&quot;: &quot;string&quot;,     &quot;validFor&quot;: {       &quot;endDateTime&quot;: &quot;2020-10-11T19:06:40.586Z&quot;,       &quot;startDateTime&quot;: &quot;2020-10-11T19:06:40.586Z&quot;}}
  </code></pre>
  <p><a href="https://i.stack.imgur.com/BAfV0.jpg" rel="nofollow noreferrer">Postman Request</a></p>