score:3

Accepted answer

I had a similar issue. The problem is not with the validator. The problem is caused because json_encode doesn't handle certain objects nicely. In this case, if you create a string or simple array of all the errors, and then return the string/array as json, it should work.

$messages = array();
foreach($this->errors as $error){
    $messages[] = $error->getMessage();
}
$response = new Response(json_encode(
      array(
        'errors'=>$messages
      )
));
return $response;

OR

$messages = '';
foreach($this->errors as $error){
    $messages .= $error->getMessage() . ";";
}
$response = new Response(json_encode(
      array(
        'errors'=>$messages
      )
));
return $response;

This is what solved my problem with json_encode. hope it will work for you too.

EDIT: It looks like the validator returns a resource. json_encode cannot encode resources. see php docs


Related Query

More Query from same tag