title: Spring Boot and Angular: JSON parse error: Can not deserialize instance of java.util.HashSet out of VALUE_STRING token
body: <p>I'm setting an authentication model with Spring Boot and Angular. When I complete the signup form it shows me this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Signup failed!
  " JSON parse error: Can not deserialize instance of java.util.HashSet out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.HashSet out of VALUE_STRING token at [Source: java.io.PushbackInputStream@57abbf9f; line: 1, column: 112] (through reference chain: com.steg.authentication.message.request.SignUpForm["role"]) "
  </code></pre>
  
  <p>authRESTAPI:</p>
  
  <pre><code>@CrossOrigin(origins = "*", maxAge = 3600)
    @RestController
    @RequestMapping("/api/auth")
    public class AuthRestAPIs {
  
  @Autowired
  AuthenticationManager authenticationManager;
  
  @Autowired
  UserRepository userRepository;
  
  @Autowired
  RoleRepository roleRepository;
  
  @Autowired
  PasswordEncoder encoder;
  
  @Autowired
  JwtProvider jwtProvider;
  
  @PostMapping("/signin")
  public ResponseEntity&lt;?&gt; authenticateUser(@Valid @RequestBody LoginForm 
  loginRequest) {
  
      Authentication authentication = authenticationManager.authenticate(
              new 
  UsernamePasswordAuthenticationToken(loginRequest.getUsername(), 
  loginRequest.getPassword()));
  
  SecurityContextHolder.getContext().setAuthentication(authentication);
  
      String jwt = jwtProvider.generateJwtToken(authentication);
      UserDetails userDetails = (UserDetails) 
      authentication.getPrincipal();
  
      return ResponseEntity.ok(new JwtResponse(jwt, 
      userDetails.getUsername(), userDetails.getAuthorities()));
        }
      @PostMapping("/signup")
      public ResponseEntity&lt;?&gt; registerUser(@Valid @RequestBody SignUpForm 
      signUpRequest) {
      if (userRepository.existsByUsername(signUpRequest.getUsername())) {
          return new ResponseEntity&lt;&gt;(new ResponseMessage("Fail -&gt; Username 
              is already taken!"),
                  HttpStatus.BAD_REQUEST);
      }
  
      if (userRepository.existsByEmail(signUpRequest.getEmail())) {
          return new ResponseEntity&lt;&gt;(new ResponseMessage("Fail -&gt; Email is 
       already in use!"),
                  HttpStatus.BAD_REQUEST);
      }
  
      // Creating user's account
      User user = new 
      User(signUpRequest.getNom(),signUpRequest.getPrenom(), 
      signUpRequest.getUsername(), signUpRequest.getEmail(),
              encoder.encode(signUpRequest.getPassword()));
  
      Set&lt;String&gt; strRoles = signUpRequest.getRole();
      Set&lt;Role&gt; roles = new HashSet&lt;&gt;();
  
      strRoles.forEach(role -&gt; {
          switch (role) {
          case "admin":
              Role adminRole = 
      roleRepository.findByName(RoleName.ROLE_ADMIN)
                      .orElseThrow(() -&gt; new RuntimeException("Fail! -&gt; 
                        Cause: User Role not find."));
              roles.add(adminRole);
  
              break;
          default:
              Role userRole = roleRepository.findByName(RoleName.ROLE_USER)
                      .orElseThrow(() -&gt; new RuntimeException("Fail! -&gt; 
                              Cause: User Role not find."));
              roles.add(userRole);
          }
      });
  
      user.setRoles(roles);
      userRepository.save(user);
  
      return new ResponseEntity&lt;&gt;(new ResponseMessage("User registered 
                             successfully!"), HttpStatus.OK);
                 }    
       }
  </code></pre>
  
  <p>Angular register.component.ts:</p>
  
  
  
  <pre><code>      import { Component, OnInit } from '@angular/core';
  
        import { AuthService } from '../auth/auth.service';
        import { SignUpInfo } from '../auth/signup-info';
  
        @Component({
        selector: 'app-register',
        templateUrl: './register.component.html',
        styleUrls: ['./register.component.css']
            })
        export class RegisterComponent implements OnInit {
        form: any = {};
        signupInfo: SignUpInfo;
        isSignedUp = false;
        isSignUpFailed = false;
        errorMessage = '';
  
        topics:string[] = ['admin','user'];
  
        constructor(private authService: AuthService) { }
  
           ngOnInit() { }
  
           onSubmit() {
            console.log(this.form);
  
  
            this.signupInfo = new SignUpInfo(
              this.form.nom,
              this.form.prenom,
              this.form.username,
              this.form.email,
              this.form.password,
              this.form.role
                  );
  
              this.authService.signUp(this.signupInfo).subscribe(
                data =&gt; {
             console.log(data);
             this.isSignedUp = true;
             this.isSignUpFailed = false;
    },
    error =&gt; {
      console.log(error);
      this.errorMessage = error.error.message;
      this.isSignUpFailed = true;
    }
  );
  }
  }
  </code></pre>
  
  <p>Angular signup service:</p>
  
  
  
  <pre><code>    import { Injectable } from '@angular/core';
      import { HttpClient, HttpHeaders } from '@angular/common/http';
      import { Observable } from 'rxjs';
  
      import { JwtResponse } from './jwt-response';
      import { AuthLoginInfo } from './login-info';
      import { SignUpInfo } from './signup-info';
  
      const httpOptions = {
             headers: new HttpHeaders({ 'Content-Type': 'application/json' 
                       })
                    };
  
      @Injectable({
          providedIn: 'root'
                  })
      export class AuthService {
  
      private loginUrl = 'http://localhost:8080/api/auth/signin';
      private signupUrl = 'http://localhost:8080/api/auth/signup';
  
        constructor(private http: HttpClient) {
                 }
  
        attemptAuth(credentials: AuthLoginInfo): Observable &lt;JwtResponse&gt;  
          {
           return this.http.post &lt;JwtResponse&gt; (this.loginUrl, credentials, 
          httpOptions);
           }
  
          signUp(info: SignUpInfo): Observable &lt;any&gt; {
           return this.http.post &lt;string&gt; (this.signupUrl, info, 
           httpOptions);
            }
            }
  </code></pre>