title: JSON parse error: Cannot deserialize instance of `java.util.HashSet` out of VALUE_STRING token;
body: <p><strong>JSON parse error: Cannot deserialize instance of <code>java.util.HashSet</code> out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of <code>java.util.HashSet</code> out of VALUE_STRING token</strong></p>
  <p>I was getting the above error when i use Post request to call my REST API from my Angular code.
  After going through similar questions posted here, i've understood my JSON Object is not getting formatted properly while making the Post request. The code below is a properly formatted JSON POST Request.</p>
  <pre><code>{
      &quot;id&quot;: 7,
      &quot;name&quot;: &quot;Vinay&quot;,
      &quot;email&quot;: &quot;vinay@gmail.com&quot;,
      &quot;phone&quot;: &quot;9876500111&quot;,
      &quot;address&quot;: &quot;Sector-65, Chandigarh&quot;,
      &quot;stateID&quot;: 9,
      &quot;cityID&quot;: 6,
      &quot;dateOfBirth&quot;: &quot;01/03/1979&quot;,
      &quot;courses&quot;: [
          &quot;Java&quot;,
          &quot;C++&quot;,
          &quot;Python&quot;
      ]
  }
  </code></pre>
  <p>But when I submit the request in Angular, the nested array &quot;courses&quot; is not getting formatted properly with [] brackets.</p>
  <pre><code>Object { name: &quot;Rajesh&quot;, email: &quot;rajesh@gmail.com&quot;, phone: &quot;9876543210&quot;, address: &quot;Sector - 4, Chandigarh&quot;, dateOfBirth: &quot;01/03/2001&quot;, courses: &quot;Java&quot; }
  </code></pre>
  <p>student.ts</p>
  <pre><code>export class Student {
      id: number;
      name: string;
      email: string;
      phone: string;
      address: string;
      dateOfBirth: string;
      courses: [];
  }
  </code></pre>
  <p>create-student.component.html</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="col-md-6 offset-md-3"&gt;
  &lt;h3&gt;Create Student&lt;/h3&gt;
  &lt;form (ngSubmit) = "onSubmit()"&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Student Name&lt;/label&gt;
          &lt;input type="text" class="form-control" id="studentName"
                  [(ngModel)] = "student.name" name="studentName"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input type="text" class="form-control" id="email"
                  [(ngModel)] = "student.email" name="email"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Phone&lt;/label&gt;
          &lt;input type="text" class="form-control" id="phone"
                  [(ngModel)] = "student.phone" name="phone"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Address&lt;/label&gt;
          &lt;input type="text" class="form-control" id="address"
                  [(ngModel)] = "student.address" name="address"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Date of Birth&lt;/label&gt;
          &lt;input type="text" class="form-control" id="dateOfBirth"
                  [(ngModel)] = "student.dateOfBirth" name="dateOfBirth"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Courses&lt;/label&gt;
          &lt;input type="text" class="form-control" id="courses"
                  [(ngModel)] = "student.courses" name="courses"&gt;
      &lt;/div&gt;
      &lt;button class="btn btn-success" type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>create-student.component.ts</p>
  <pre><code>export class CreateStudentComponent implements OnInit {
  
    student: Student = new Student(); 
  
    constructor(private studentService: StudentService,
      private router: Router) { }
  
    ngOnInit(): void {
    }
  
    saveStudent(){
      
      this.studentService.createStudent(this.student).subscribe(data =&gt;{
        console.log(&quot;data:&quot;+data);
        this.goToStudentList();
      },
      error=&gt; console.log(error));
    }
  
    goToStudentList(){
      this.router.navigate(['/students']);
    }
  
    onSubmit(){
      console.log(this.student);
      console.log(&quot;Json:&quot;+JSON.stringify(this.student));
      this.saveStudent();
    }
  
  </code></pre>