I'm working on a Symfony application, and I have a User entity :
/**
* @ORM\Entity
* @ORM\Table(name="user")
* @Serializer\ExclusionPolicy("all")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Serializer\Expose()
*/
private $id;
/**
* @var string $email
*
* @ORM\Column(name="email", type="string", length=255, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
* @Serializer\Expose()
*/
private $email;
/**
* @ORM\Column(type="string", length=64)
* @Assert\NotBlank()
*/
private $password;
}
I'm trying to deserialize the request payload to my entity like so :
$data = $this->request->request->all();
$jsonContent = $this->serializer->serialize($data, 'json'); // serializing goes fine
dump($jsonContent);
{
"email":"[email protected]",
"password":"123"
}
$object = $this->serializer->deserialize($jsonContent, User::class, 'json');
dump($object); // I'm getting null values
AppBundle\Entity\User {
-id: null
-email: null
-password: null
}
so when I try to validate my object using the validator :
$errors = $this->validator->validate($object);
the validation fails with this response :
{
"errors" :
{
"email": "This value should not be blank.",
"password": "This value should not be blank."
}
}
but, when I remove this line @Serializer\ExclusionPolicy("all") everything works fine.
I'm using :
- Symfony 3.4
- jms/serializer-bundle 2.3
How can I solve this issue ?