title: getRole() form RoleInterface returns empty on symfony
body: <p>i have a big problem implementing JWT Tokens on symfony.
  I already make work the JWT token, but i need to add to the token info the User roles too. i am doing this using a Listener (JWTCreatedListener):</p>
  
  <pre><code>public function onJWTCreated(JWTCreatedEvent $event)
  {
      $request = $this-&gt;requestStack-&gt;getCurrentRequest();
  
      $payload       = $event-&gt;getData();
      $payload['ip'] = $request-&gt;getClientIp();
      $payload['roles'] = $event-&gt;getUser()-&gt;getRoles();
  
      $event-&gt;setData($payload);
  }
  </code></pre>
  
  <p>I implemented the Role.php (AppBundle/Entity/Role.php) on this way:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Symfony\Component\Security\Core\Role\RoleInterface;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Table(name="acme_role")
   * @ORM\Entity()
   */
  class Role implements RoleInterface
  {
      /**
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id()
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(name="name", type="string", length=30)
       */
      private $name;
  
      /**
       * @ORM\Column(name="role", type="string", length=20, unique=true)
       */
      private $role;
  
      /**
       * @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
       */
      private $users;
  
      public function __construct()
      {
          $this-&gt;users = new ArrayCollection();
      }
  
      /**
       * @see RoleInterface
       */
      public function getRole()
      {
          return $this-&gt;role;
      }
  
      // ... getters and setters for each property
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       *
       * @return Role
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * Set role
       *
       * @param string $role
       *
       * @return Role
       */
      public function setRole($role)
      {
          $this-&gt;role = $role;
  
          return $this;
      }
  
      /**
       * Add user
       *
       * @param \AppBundle\Entity\User $user
       *
       * @return Role
       */
      public function addUser(\AppBundle\Entity\User $user)
      {
          $this-&gt;users[] = $user;
  
          return $this;
      }
  
      /**
       * Remove user
       *
       * @param \AppBundle\Entity\User $user
       */
      public function removeUser(\AppBundle\Entity\User $user)
      {
          $this-&gt;users-&gt;removeElement($user);
      }
  
      /**
       * Get users
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getUsers()
      {
          return $this-&gt;users;
      }
  }
  </code></pre>
  
  <p>And my User class:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * @ORM\Table(name="users")
   * @ORM\Entity
   */
  class User implements AdvancedUserInterface, \Serializable
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=25, unique=true)
       */
      private $username;
  
      /**
       * @ORM\Column(type="string", length=500)
       */
      private $password;
  
      /**
       * @ORM\Column(name="is_active", type="boolean")
       */
      private $isActive;
  
      /**
       * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
       * 
       */
      private $roles;
  
      public function __construct($username)
      {
          $this-&gt;isActive = true;
          $this-&gt;username = $username;
          $this-&gt;roles = new ArrayCollection();
      }
  
      public function getUsername()
      {
          return $this-&gt;username;
      }
  
      public function getSalt()
      {
          return null;
      }
  
      public function getPassword()
      {
          return $this-&gt;password;
      }
  
      public function setPassword($password)
      {
          $this-&gt;password = $password;
      }
  
      public function getRoles()
      {
           return $this-&gt;roles-&gt;toArray();
      }
  
      public function eraseCredentials()
      {
      }
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set username
       *
       * @param string $username
       *
       * @return User
       */
      public function setUsername($username)
      {
          $this-&gt;username = $username;
  
          return $this;
      }
  
      /**
       * Set isActive
       *
       * @param boolean $isActive
       *
       * @return User
       */
      public function setIsActive($isActive)
      {
          $this-&gt;isActive = $isActive;
  
          return $this;
      }
  
      /**
       * Get isActive
       *
       * @return boolean
       */
      public function getIsActive()
      {
          return $this-&gt;isActive;
      }
  
      /**
       * Add role
       *
       * @param \AppBundle\Entity\Role $role
       *
       * @return User
       */
      public function addRole(\AppBundle\Entity\Role $role)
      {
          $this-&gt;roles[] = $role;
  
          return $this;
      }
  
      /**
       * Remove role
       *
       * @param \AppBundle\Entity\Role $role
       */
      public function removeRole(\AppBundle\Entity\Role $role)
      {
          $this-&gt;roles-&gt;removeElement($role);
      }
  
      public function isAccountNonExpired()
      {
          return true;
      }
  
      public function isAccountNonLocked()
      {
          return true;
      }
  
      public function isCredentialsNonExpired()
      {
          return true;
      }
  
      public function isEnabled()
      {
          return $this-&gt;isActive;
      }
  
      // serialize and unserialize must be updated - see below
      public function serialize()
      {
          return serialize(array(
              // ...
              $this-&gt;isActive
          ));
      }
      public function unserialize($serialized)
      {
          list (
              // ...
              $this-&gt;isActive
          ) = unserialize($serialized);
      }
  }
  </code></pre>
  
  <p>The problem is that this method getRole() always returns empty.</p>
  
  <p>This is my db data:</p>
  
  <pre><code>[users]
      id  username  password                                           is_active
      1  abriceno  $2y$13$NW6uNOKJGUQTSXirej4HKOwIa6mWzYqFxzz1ppWQjyp... 1
  
  [acme_role]
  id  name    role
  1   admin   ROLE_ADMIN
  
  [user_role]
  user_id user_role
  1        1
  </code></pre>
  
  <p>Also, i try to call the data from a controller test using doctrine:</p>
  
  <pre><code>public function indexAction(Request $request)
      {
  
         $repository = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:User');
          $user = $repository-&gt;findOneByusername('abriceno');
  
  
          $username = $user-&gt;getUsername();
          $roles = $user-&gt;getRoles();
  
          $arr = array(
              'username' =&gt; $user-&gt;getUsername(),
              'password' =&gt; $user-&gt;getPassword(),
              'roles' =&gt; $user-&gt;getRoles()
          );
         return new JsonResponse($arr);
  </code></pre>
  
  <p>this returns:</p>
  
  <pre><code>{"username":"abriceno","password":"$2y$13$NW6uNOKJGUQTSXirej4HKOwIa6mWzYqFxzz1ppWQjypQJLIgUGJ.m","roles":[{}]}
  </code></pre>
  
  <p>I am so desperate... thanks for all the help that you can provide to me.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>If i do print_r($role) this prints a huuuuuge list of values:</p>
  
  <pre><code>array(1) { [0]=&gt; object(AppBundle\Entity\Role)#624 (4) { ["id":"AppBundle\Entity\Role":private]=&gt; int(1) ["name":"AppBundle\Entity\Role":private]=&gt; string(5) "admin" ["role":"AppBundle\Entity\Role":private]=&gt; string(10) "ROLE_ADMIN" ["users":"AppBundle\Entity\Role":private]=&gt; object(Doctrine\ORM\PersistentCollection)#626 (9) { ["snapshot":"Doctrine\ORM\PersistentCollection":private]=&gt; array(0) { } ["owner":"Doctrine\ORM\PersistentCollection":private]=&gt; *RECURSION* 
  </code></pre>
  
  <p>... and keeps going... very strange!!</p>