Open vrobinsonscs opened 6 years ago
Greetings,
Because json_encode
does not know how to encode your objects, you need to define a key for each property you need to expose by calling getters explicitly, and that for all your object hierarchy.
I suggest to have a look at the symfony serializer, if your objects are exposing the relevant properties via getters, the following code would normalize them to a clean array:
$approles = $this->serializer->normalize($person->getAppRoles(), \Symfony\Component\Serializer\Encoder\JsonEncoder::FORMAT)
Apologies for the tardy acknowledgement, but thank you for the speedy response on your part.
Very intriguing idea. We're using the JSS Serializer, but perhaps there's no reason we couldn't invoke the Symfony serializer for this purpose. We'll give it a try.
Greetings -
Sincere apologies if this has been asked about, but haven't found any similar discussions, other than the slightly related https://github.com/lexik/LexikJWTAuthenticationBundle/issues/362.
We'd like to return a list of roles after successful login, which relies on a property that is a collection, rather than a simple string or integer. However, grabbing that property in the AuthenticationSuccessListener results in an empty array -- though interestingly, with the correct number of elements.
It looks to me like the Doctrine entities are not fully formed -- no constructor seems to be run, for example. Is there a way to get the objects fully hydrated? Is there a Use statement that might help? If not, then please consider this a feature request.
In the meantime, I have a working solution, FWIW:
Noticing that I can get plain text and integer properties of related objects, I iterated the seemingly empty related objects and populated a new array with the resulting values, which worked.