title: Deserialization of File type from Angular to Java using Jackson
body: <p>In my REST application developed using SpringBoot and Angular, I need to send a REST request to SpringBoot back end in order to save a object into the database. </p>
  
  <p>In the front end, user fills up a form and submits. Following is the interface from which a object is created in order to be sent to the backend as a REST call.</p>
  
  <pre><code>export interface TenderToPost{
  
      id: number;
      name: string;
      description: string;
      images: File[];
      referenceNumber: string;
  
  }
  </code></pre>
  
  <p>The backend should deserialize the above object to a object of Following class in Java.</p>
  
  <pre><code>public class TenderDTO implements Serializable{
  
      private long id;
  
      private String name;
  
      private String description;
  
      private List&lt;MultipartFile&gt; images;
  
      private String referenceNumber;
  
      // default constructor
  
      // geters and setters
  
  }
  </code></pre>
  
  <p>As shown above, I need to accept the File sent from frontend as a <code>MultipartFile</code>. </p>
  
  <p>However, when the request is sent from the front end, Jackson gives me the error </p>
  
  <blockquote>
    <p>Can not construct instance of
    org.springframework.web.multipart.MultipartFile: abstract types either
    need to be mapped to concrete types, have custom deserializer, or
    contain additional type information</p>
  </blockquote>
  
  <p>I am aware that that this error comes since I have used <code>MultipartFile</code> interface as the type of my images list. </p>
  
  <p>What I thought of as the solution for this, is letting Jackson know to what type the list should be deserialized into using an annotation. So, I used following</p>
  
  <pre><code>@JsonDeserialize(contentAs = CommonsMultipartFile.class)
  private List&lt;MultipartFile&gt; images;
  </code></pre>
  
  <p>CommonsMultipartFile is an implementation of <code>MultipartFile</code>. That is why I used it.</p>
  
  <p>Now I get the following error.</p>
  
  <blockquote>
    <p>Can not construct instance of
    org.springframework.web.multipart.commons.CommonsMultipartFile: no
    suitable constructor found, can not deserialize from Object value
    (missing default constructor or creator, or perhaps need to add/enable
    type information?)</p>
  </blockquote>
  
  <p>Do I need to change the setter for the images list? Or is my whole approach incorrect?</p>
  
  <p>Kindly show me the way how I should correct this.</p>