title: I am facing **JSON parse error: Cannot deserialize instance of `java.util.HashSet` out of START_OBJECT token** in Spring Boot project
body: <p>I am getting <strong>JSON parse error: Cannot deserialize instance of <code>java.util.HashSet</code> out of START_OBJECT token</strong>, with my Spring Boot project, when I am trying to save Pojo class object which is mapped with <strong>One-To-Many relationship</strong> with my another Pojo. I am not sure whether I am sending the right format of JSON in Postman. I am trying to save values of a persistent class that has a Collection element Set defined.</p>
  
  <p>The Parent Pojo class:</p>
  
  <pre><code>package com.example.demo.model;
  
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "vendor")
  public class Vendor {
  
      @Id
      int vendorId;
  
      @Column
      String vendorName;
  
      @OneToMany(fetch = FetchType.LAZY, targetEntity = Customer.class, cascade = CascadeType.ALL)
      @JoinColumn(name = "vendorId")
  
      Set children;
  
      public int getVendorId() {
          return vendorId;
      }
  
      public void setVendorId(int vendorId) {
          this.vendorId = vendorId;
      }
  
      public String getVendorName() {
          return vendorName;
      }
  
      public void setVendorName(String vendorName) {
          this.vendorName = vendorName;
      }
  
      public Set getChildren() {
          return children;
      }
  
      public void setChildren(Set children) {
          this.children = children;
      }
  } 
  </code></pre>
  
  <p>Child Pojo Class:</p>
  
  <pre><code>package com.example.demo.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  import org.hibernate.annotations.GeneratorType;
  
  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
  
  @Entity
  @Table(name = "customer")
  public class Customer {
  
      @Id
      @GeneratedValue(strategy= GenerationType.AUTO)
      int customerId;
  
      @Column
      String customerName;
  
      public int getCustomerId() {
          return customerId;
      }
  
      public void setCustomerId(int customerId) {
          this.customerId = customerId;
      }
  
      public String getCustomerName() {
          return customerName;
      }
  
      public void setCustomerName(String customerName) {
          this.customerName = customerName;
      }
  
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>package com.example.demo.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.example.demo.model.Vendor;
  import com.example.demo.service.VendorDataSaveService;
  
  @RestController
  public class VendorSaveController {
  
      @Autowired
      private VendorDataSaveService dataSaveService;
  
      @PostMapping("/save")
      public void saveVendor(@RequestBody Vendor vendor) {
          dataSaveService.saveVendorRecord(vendor);
      }
  }
  </code></pre>
  
  <p>Service class:</p>
  
  <pre><code>package com.example.demo.service;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.example.demo.model.Vendor;
  import com.example.demo.repository.VendorDataSaveRepository;
  
  @Service
  public class VendorDataSaveService {
  
      @Autowired
      private VendorDataSaveRepository repository;
  
      public void saveVendorRecord(Vendor vendor) {
          repository.save(vendor);
      }
  }
  </code></pre>
  
  <p>Repository class:</p>
  
  <pre><code>package com.example.demo.repository;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  
  import com.example.demo.model.Vendor;
  
  public interface VendorDataSaveRepository extends JpaRepository&lt;Vendor, Integer&gt; {
  
  }
  </code></pre>
  
  <p>The JSON Format I have Sent from Postman:</p>
  
  <pre><code>    "vendorId" : 101,
      "vendorName" : "JAIN BOOKS",
      "children" : {
                      "customerId" : 1,
                      "customerName" : "AMIT"
                   }
  }
  </code></pre>
  
  <p>I am getting this error message on console:- </p>
  
  <blockquote>
    <p>Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of <code>java.util.HashSet</code> out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of <code>java.util.HashSet</code> out of START_OBJECT token
     at [Source: (PushbackInputStream); line: 4, column: 15] (through reference chain: com.example.demo.model.Vendor["children"])</p>
  </blockquote>
  
  <p>What do I need to improve?</p>