title: java.lang.IllegalArgumentException: Target object must not be null JAX-RS
body: <p>I'm developing a web application using JAX-RS, AngularJS, Spring Boot and Spring MVC.</p>
  
  <p>I am looking to add a car in my database which must be unique. So I did this:</p>
  
  <ul>
  <li><p>Cars.java:    </p>
  
  <pre><code>@Entity  @Table(name = "idCars",uniqueConstraints = @UniqueConstraint(columnNames = {"name", "idAidCars"}))
      public class Actifs implements Serializable {
  
          @Id
          @GeneratedValue(strategy=GenerationType.IDENTITY)
          @Column(name="idCars")
          private long idCars;
  
          @Column(name="Name") 
          private String Name;
      }
  </code></pre></li>
  <li><p>CarsRestController.java:</p></li>
  </ul>
  
  <blockquote>
  <pre><code>@CrossOrigin("*")
  @RestController
  @RequestMapping(value="/Cars")
  public class CarsRestController {
  
  // Add car in DB
  @RequestMapping(value="/Add",method = {RequestMethod.POST, RequestMethod.GET})
    public Cars AddCars(@RequestBody(required=false) @Valid Cars cars){
        return repository.save(cars); // object is NULL
    }
  
  }
  </code></pre>
  </blockquote>
  
  <ul>
  <li>AngularJS:</li>
  </ul>
  
  <blockquote>
  <pre><code>$scope.AddCars=function(){
   var dataObj = {
                    name :  $scope.name  
            };  
    console.log("Name of car "+$scope.name) // BMW
  
  var res = $http.post("/Cars/Add", dataObj);
  res.success(function(data, status, headers, config) {
      $scope.message = data;
      console.log("** "+JSON.stringify(data)); // Nothing displayed
  });
  res.error(function(data, status, headers, config) {
      alert( "failure message: " + JSON.stringify({data: data}));
    });     
  $scope.name='';
  };
  </code></pre>
  </blockquote>
  
  <ul>
  <li>Html Form:</li>
  </ul>
  
  <blockquote>
  <pre><code>&lt;form role="form" enctype="multipart/form-data" name="myForm" &gt;
  &lt;label for="name"&gt;Name Cars *:&lt;/label&gt; 
  &lt;input type="text" ng-model="name" required="required"&gt;   
  &lt;button type="submit" ng-click="AddCars()"&gt; Add Cars &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  </blockquote>
  
  <p>After an add-on test I always have the object sent from angularJS to API rest is always NULL, I do not know why?</p>
  
  <blockquote>
    <p>Target object must not be null; nested exception is
    java.lang.IllegalArgumentException: Target object must not be null</p>
  </blockquote>
  
  <p>How to correct this problem?</p>
  
  <ul>
  <li><p>WebSecurityConfig</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(securedEnabled=true)
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
              @Autowired
                protected void globalConfig(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception {
               //auth.inMemoryAuthentication().withUser("user").password("123").roles("USER");
                   auth.jdbcAuthentication()
                       .dataSource(dataSource)
                       .passwordEncoder(passwordEncoder())
                       .usersByUsernameQuery("select username as principal, password as credentials, etat as actived from utilisateurs where username=?")
                       .authoritiesByUsernameQuery("select u.username as principal, ur.nom_role as role from utilisateurs u inner join roles ur on(u.roles_id=ur.id_role) where u.username=?")
                       .rolePrefix("ROLE_");
               }
          protected void configure(HttpSecurity http) throws Exception {
  
          http
                    .sessionManagement().maximumSessions(100).maxSessionsPreventsLogin(false).expiredUrl("/Login");
                    http
                     .authorizeRequests()
                     .antMatchers("/images/**","/pdf/**","/Template/**","/Views/**","/MainApp.js","/css/**", "/js/**").permitAll()
                     .antMatchers("/Cars/**").access("hasRole('ADMIN')")
          .antMatchers("/Login").anonymous()
                     .anyRequest().authenticated()
                     .and()
                     .exceptionHandling().accessDeniedPage("/403")
                     .and()
                     .formLogin().loginPage("/Login").permitAll()
                     .defaultSuccessUrl("/", true)  
                     .failureUrl("/Login?error=true")
                         .and()
                         .csrf()
                         .and()
                          .rememberMe().tokenRepository(persistentTokenRepository())
                          .tokenValiditySeconds(360000); 
          }
  </code></pre>
  
  <p>Thank you,</p></li>
  </ul>