title: Jackson Polymorphic Deserialization with Spring Boot | JSON parse error: Unexpected end-of-input within/between Object entries
body: <p>I am using @JsonTypeInfo and @JsonSubTypes to serialize/deserialize the entity.</p>
  
  <p>Below is code which I am doing</p>
  
  <ol>
  <li>OrganizationDTO.java</li>
  </ol>
  
  <pre><code>public class OrganizationDTO {
      private long id;
      private String name;
      List&lt;? extends EmployeeDTO&gt; employees;
      //getter and setter
  }
  </code></pre>
  
  <ol start="2">
  <li>EmployeeDTO.java (Parent class)</li>
  </ol>
  
  <pre><code>@JsonTypeInfo(
          use = JsonTypeInfo.Id.NAME,
          include = JsonTypeInfo.As.PROPERTY,
          property = "type")
  @JsonSubTypes({
          @Type(value = FullTimeEmployeeDTO.class, name = "full"),
          @Type(value = PartTimeEmployeeDTO.class, name = "part")
  })
  public abstract class EmployeeDTO {
      private long id;
      private String name;
      //getter and setter
  }
  </code></pre>
  
  <ol start="3">
  <li>FullTimeEmployeeDTO.java (Child Class)</li>
  </ol>
  
  <pre><code>@JsonTypeName("full")
  public class FullTimeEmployeeDTO extends EmployeeDTO {
      private int salary;
      //getter and setter
  }
  </code></pre>
  
  <ol start="4">
  <li>PartTimeEmployeeDTO.java (Child Class)</li>
  </ol>
  
  <pre><code>@JsonTypeName("part")
  public class PartTimeEmployeeDTO extends EmployeeDTO {
      private int hourlyRate;
      //getter and setter
  }
  </code></pre>
  
  <ol start="5">
  <li>Organization Controller</li>
  </ol>
  
  <pre><code>@PostMapping
  public ResponseEntity&lt;ResponseUtil&lt;Employee&gt;&gt; save(@RequestBody OrganizationDTO organization) {     
          organizationService.save(organization);
          return new ResponseEntity&lt;&gt;(new ResponseUtil&lt;Employee&gt;("Data Saved Successfully."), HttpStatus.CREATED);
  }
  </code></pre>
  
  <p>I am trying to call this endpoint from postman with this below data.</p>
  
  <pre><code>{
      "name": "My Organization",
      "employees": [
          {
              "type": "full",
              "name": "Vinit Solanki",
              "salary": 200
          },
          {
              "type": "full",
              "name": "Viren Shah",
              "salary": 300
          }
      ]
  }
  </code></pre>
  
  <p>I am getting the exception as below.</p>
  
  <pre><code>{
      "timestamp": "2019-11-29T10:35:29.146+0000",
      "status": 400,
      "error": "Bad Request",
      "message": "JSON parse error: Unexpected end-of-input within/between Object entries; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected end-of-input within/between Object entries\n at [Source: (PushbackInputStream); line: 10, column: 21] (through reference chain: com.example.demo.dto.OrganizationDTO[\"employees\"]-&gt;java.util.ArrayList[1])",
      "path": "/organizations"
  }
  </code></pre>
  
  <p>I wonder the same implementation is working while trying to convert the string JSON to <code>OrganizationDTO</code> object via <code>readValue()</code>. Below is an example of it.</p>
  
  <pre><code>
      public static void main(String[] args) throws JsonProcessingException {
          ObjectMapper mapper = new ObjectMapper();
  
          OrganizationDTO orgDTO = mapper.readValue(
                  "{\n" +
                          "    \"name\": \"My Organization\",\n" +
                          "    \"employees\": [\n" +
                          "        {\n" +
                          "            \"type\": \"full\",\n" +
                          "            \"name\": \"Vinit Solanki\",\n" +
                          "            \"salary\": 200\n" +
                          "        },\n" +
                          "        {\n" +
                          "            \"type\": \"full\",\n" +
                          "            \"name\": \"Vinit Solanki\",\n" +
                          "            \"salary\": 130\n" +
                          "        }\n" +
                          "    ]\n" +
                          "}",
                  OrganizationDTO.class);
  
      }
  </code></pre>
  
  <p>Does anyone know why I'm getting this error? Thanks.</p>