title: Return JSON object from a spring-boot rest Controller
body: <p>I'm trying to check if the username is unique in spring-boot.
  I want to send the result as JSON object.
  This is the REST controller</p>
  
  <pre><code>@RequestMapping(value="/checkEmailUnique",method=RequestMethod.POST)
  public String checkEmailUnique(@RequestBody String username){
  
      AppUser app = userRepo.findByUsername(username);
      if(app!=null){
          // I want to return somthing like emailNotTaken: true
      }
      else{
          // and here : emailNotTaken: false  
      }
  }
  </code></pre>
  
  <p>I want to get the result in angular so I can show an error message in my component.
  How can I do that?</p>
  
  <p><strong>Angular side</strong></p>
  
  <p>client.Service.Ts</p>
  
  <pre><code>checkEmailNotTaken(email:string){
      if(this.authService.getToken()==null) {
        this.authService.loadToken();
      }
      return this.http.post(this.host+
        "/checkEmailUnique/",{email},{headers:new HttpHeaders({'Authorization':this.authService.getToken()})});
    }
  </code></pre>
  
  <p>in client.component.ts</p>
  
  <pre><code>ngOnInit() {
  
      this.form = this.formBuilder.group({
        prenom: ['', Validators.required],
        nom: ['', Validators.required],
        tel: ['', Validators.required],
        cin: ['', Validators.required],
        username: ['', Validators.required , Validators.email  , this.validateEmailNotTaken.bind(this)],
        passwordG: this.formBuilder.group({
          password: ['',[Validators.required,Validators.minLength(9)]],
          Confirmationpassword : ['',[Validators.required,Validators.minLength(9)]]
  
        }, {validator: passwordMatch})
  
      });
    }
  
      validateEmailNotTaken(control: AbstractControl) {
          return this.clientService.checkEmailNotTaken(control.value).map(res =&gt; {
            return  // what to do here ?
          });
  
        }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>@RequestMapping(value="/checkEmailUnique",method=RequestMethod.POST)
      public EmailStatusCheckJson checkEmailUnique(@RequestBody final String username){
  
          final EmailStatusCheckJson returnValue = new EmailStatusCheckJson();
  
  
           AppUser app = userRepo.findByUsername(username);
  
  
           if(app!=null){
               returnValue.setEmailIsAvailable(false);
           }
           else{
               returnValue.setEmailIsAvailable(true);
  
           }
  
           return returnValue;
      }
  </code></pre>