Getting the following error? Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL
I was getting it while trying to login a user. The thing was, in my Role entity, all properties were private.
-
class Role implements RoleInterface
-
{
-
private $id;
-
-
private $name;
-
-
private $created_at;
-
-
// …
-
}
When doing some googling and checking things out, I found this comment on php.net which gave me an idea. I changed all private properties to protected and thing worked!
-
class Role implements RoleInterface
-
{
-
protected $id;
-
-
protected $name;
-
-
protected $created_at;
-
-
// …
-
}

thanks a lot.. you made me able to progress my work on the project with upgraded versions of symfony
Thank You, that helped me!
In my case, the problem was in one of my other entities, but related to User as well.
By the way, I’m wondering, why entities fields are generated with ‘private’ keyword if that problem exists..
I have got the same problem :/
but in my case it is because my User entity uses an relationship with Group. so the serialize crashes :/
how can I fix it ?
please, reply in my email. thx.
I think that making all properties in User aswell as in Group entity protected should do the trick.
Just don’t use the private access modifier.