title: How to validate an array of strings in Symfony?
body: <p>in a User entity I have a field called &quot;roles&quot; which is an array.
  I want to be able to validate it to allow only specific strings (role names) I tried this:</p>
  <pre><code>&lt;?php
  use Symfony\Component\Validator\Constraints\Collection;
  use Symfony\Component\Validator\Constraints\Type;
      class User{
          #[Collection(['ROLE_USER' =&gt; new Type('string'), 'ROLE_ADMIN' =&gt; new Type('string')])]
          #[ORM\Column(type: 'json')]
          private $roles = [];
      }
  </code></pre>
  <p>But thats not working as expected. I get this when I validate:</p>
  <pre><code>roles[ROLE_USER]: This field is missing.
  roles[ROLE_ADMIN]: This field is missing.
  roles[0]: This field was not expected.
  </code></pre>
  <p>I set the user role like this:</p>
  <pre><code>$user = new User();
  $user-&gt;setRoles([$request-&gt;get('role')]);
  </code></pre>
  <p>I am not sure if I should use Collection constraint here. It should be allowed to save an array with only these values &quot;ROLE_USER&quot; and/or &quot;ROLE_ADMIN&quot;. Any ideas?</p>