title: Invalid property `xyz` of bean class[java.util.ArrayList]: Bean property 'xyz' is not readable or has an invalid getter method
body: <p>I'm new to Spring boot. I'm having trouble with javax based validations.
  The controller expects list of json obj from POST endpoint. In the JSON request json array, 
  if <code>engine</code> or <code>name</code> is null, I get correct 400 error. But, when <code>engine.type</code> 
  or <code>engine.name</code> are null, it throws 500 exception with error message:</p>
  
  <pre><code>Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'engine' of bean class 
  [java.util.ArrayList]: Bean property 'engine' is not readable or has an invalid 
  getter method: Does the return type of the getter match the parameter type of 
  the setter?
  </code></pre>
  
  <p>Controller.java</p>
  
  <pre><code>@RestController
  @Validated
  public class CarController {
    @PostMapping(path = "/cars")
    public ResponseEntity&lt;PostModelResponse&gt; createModel(
            @Valid @RequestBody ArrayList&lt;Car&gt; cars)
            throws JSONException, ConstraintViolationException {
            ...
        return new ResponseEntity&lt;&gt;(response, HttpStatus.CREATED);
    }
  }
  </code></pre>
  
  <p>Car.java</p>
  
  <pre><code>class Car {
    @NotNull
    @Valid
    private Engine engine;
  
    @NotNull
    private String name;
  
    Cars(Engine engine, String name) {
      this.engine = engine;
      this.name = name;
    }
  
    public String getName(){ return name; }
    public void setName(String name) { this.name = name;}
    public Engine getEngine() { return engine; }
    public void setEngine(Engine engine){ this.engine = engine; }
  
  }
  </code></pre>
  
  <p>Engine.java</p>
  
  <pre><code>class Engine {
    @NotNull
    private String type;
    @NotNull
    private String name;
  
    Engine(String type, String name) {
      this.type = type;
      this.name = name;
    }
    public String getType() { return type; }
    public void setType(String type) { this.type = type; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name;}
  }
  </code></pre>
  
  <p>CollectionValidator.java</p>
  
  <pre><code>public class CollectionValidator implements Validator {
  
      private final Validator validator;
  
      public CollectionValidator(LocalValidatorFactoryBean validator) {
          this.validator = validator;
      }
  
      @Override
      public boolean supports(Class&lt;?&gt; clazz) {
          return Collection.class.isAssignableFrom(clazz);
      }
  
      @Override
      public void validate(Object target, Errors errors) {
          Collection col = (Collection) target;
          for ( Object obj : col ) {
              ValidationUtils.invokeValidator(validator, obj, errors);
          }
      }
  }
  </code></pre>
  
  <p>ValidatorAdvice.java</p>
  
  <pre><code>@ControllerAdvice
  public class ValidatorAdvice {
  
      @Autowired
      protected LocalValidatorFactoryBean validator;
  
      @InitBinder
      public void initBinder(WebDataBinder binder) {
          binder.initDirectFieldAccess();
          binder.addValidators(new CollectionValidator(validator));
      }
  }
  </code></pre>
  
  <p>Request/Responses: URL: <a href="http://localhost:8080/cars" rel="nofollow noreferrer">http://localhost:8080/cars</a></p>
  
  <ol>
  <li><p>POST Body: [{
  "name" : "Volvo",
  "engine" : {
    "type" : "v3",
    "name" : "volvo_engine"
  }
  }]</p>
  
  <p>Response: 200(OK)</p></li>
  <li><p>POST Body: [{
  "engine" : {
    "type" : "v3",
    "name" : "volvo_engine"
  }
  }]</p>
  
  <p>Response: 400(Which is expected coz <code>name</code> is missing)</p></li>
  <li><p>POST Body: [{"name" : "Volvo"}]</p>
  
  <p>Response: 400(Which is expected coz <code>engine</code> is missing)</p></li>
  <li><p>POST Body: [{
  "name" : "Volvo",
  "engine" : {
    "name" : "volvo_engine"
  }
  }]</p>
  
  <p>Response: 500(I was expecting 400) with error: </p>
  
  <p>Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'engine' of bean class 
    [java.util.ArrayList]: Bean property 'id' is not readable or has an invalid 
    getter method: Does the return type of the getter match the parameter type of 
    the setter?</p></li>
  </ol>
  
  <p>I looked at other stackOverflow results before posting this. Everything works fine if I'm accepting <code>Car</code> object instead of <code>ArrayList&lt;Car&gt;</code></p>
  
  <p>Any help is greatly appreciated.</p>