title: Spring RESTFul Client – RestTemplate. Have weird somthing,Please let me know
body: <p>I'm using ResTemplate to post User object in CLient. But When i use method postForObject then occur Unresolved compilation problem <code>The method postForObject(URI, Object, Class&lt;T&gt;) in the type RestTemplate is not applicable for the arguments (URL, User, Class&lt;User&gt;)</code>. I really don't understand ???</p>
  
  <p>Here file <code>RestClientTest</code>.java` </p>
  
  <pre><code>public class RestClientTest {
  
      public static void main(String[] args) throws IOException{
  //      System.out.println("Rest Response" + loadUser("quypham"));
  //      URL url = new URL("http://localhost:8080/rest/user/create");
  //      rt.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  //      rt.getMessageConverters().add(new StringHttpMessageConverter());
  //      Map&lt;String,String&gt; vars = new HashMap&lt;String,String&gt;();
  
          RestTemplate rt = new RestTemplate();
          User user = new User();
          user.setUserName("datpham");
          user.setPassWord("12345");
          Calendar calendar = Calendar.getInstance();
          calendar.set(Calendar.YEAR,1960);
          user.setBirthDay(calendar.getTime());
          user.setAge(12);
          String uri = new String("http://localhost:8080/rest/user/create");
          User returns = rt.postForObject(uri, user,User.class);
  
  //      createUser(user);
          System.out.println("Rest Response" + loadUser("datpham"));
      }
  </code></pre>
  
  <p>Here file <code>UserRestServiceController</code> </p>
  
  <pre><code>@Controller
  public class UserRestServiceController {
      @Autowired
      public  UserDao userDao;
      @RequestMapping(value = "/rest/user/create",method = RequestMethod.POST)
      @ResponseStatus(HttpStatus.CREATED)
      public void addUser(@RequestBody User user){
          userDao.save(user);
      }
  </code></pre>
  
  <p>I have edited <code>String uri</code> but encounter new following error:</p>
  
  <blockquote>
    <p>Mar 29, 2016 1:57:43 PM org.springframework.web.client.RestTemplate
    handleResponseError WARNING: POST request for
    "<a href="http://localhost:8080/rest/user/create" rel="nofollow">http://localhost:8080/rest/user/create</a>" resulted in 400 (Bad
    Request); invoking error handler Exception in thread "main"
    org.springframework.web.client.HttpClientErrorException: 400 Bad
    Request   at
    org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
      at
    org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:588)
      at
    org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:546)
      at
    org.springframework.web.client.RestTemplate.execute(RestTemplate.java:502)
      at
    org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:330)
      at
    edu.java.spring.service.client.RestClientTest.main(RestClientTest.java:45)</p>
  </blockquote>
  
  <p>Here User.java</p>
  
  <pre><code>@Entity
  @Table(name = "brotheruser",uniqueConstraints={@UniqueConstraint(columnNames="username")})
  @JsonIgnoreProperties(ignoreUnknown = true)
  public class User {
  //  @Enumerated(EnumType.STRING)
  //  @Column(name = "gender", nullable = false)
  //   
  //  public Gender getGender() {
  //      return gender;
  //  }
  //  public void setGender(Gender gender) {
  //      this.gender = gender;
  //  }
      @Id
      @Column(name = "username", unique = true, nullable = false)
      public String getUserName() {
          return userName;
      }
      public void setUserName(String userName) {
          this.userName = userName;
      }
      @Column(name = "password", nullable = false)
      public String getPassWord() {
          return passWord;
      }
      public void setPassWord(String passWord) {
          this.passWord = passWord;
      }
      @JsonSerialize(using = DateSerializer.class)
  //  @JsonDeserialize(using = DateDeserializer.class)
      @Column(name = "birthday", nullable = false)
      public Date getBirthDay() {
  
  
          return birthDay;
      }
  
      public void setBirthDay(Date birthDay) {
          this.birthDay = birthDay;
      }
      @Column(name="age", nullable = false)
      public Integer getAge() {
          return age;
      }
      public void setAge(Integer age) {
          this.age = age;
      }
      private String userName;
      private String passWord;
      private Date birthDay;
      private Integer age;
  
  //  private Gender gender;
  
  
  }
  </code></pre>