I make a REST API on Symfony4, So I would like to Serialize my Entity with the default serializer of Symfony4.
But my entities have unusual attribute names that make serializer give me bad result.
I tried to implement NameConverterInterface
and also tried CamelCaseToSnakeCaseNameConverter
without a good result...
Every entity on my application have this kind of attribute so a solution with @annotation can't help me
class Product implements EntityInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer", name="PROD_PKEY")
*/
private $PROD_PKEY;
/**
* @ORM\Column(type="string", length=50)
*/
private $PROD_Name;
/**
* @ORM\Column(type="string", length=50)
*/
private $PROD_Code;
And how I use the serializer :
$product = new Product();
$product->setPRODName("Name");
$product->setPRODCode("Code");
$json = $this->serializer->serialize($product, 'json');
The content of $json is :
{
"pRODName": "Name",
"pRODCode": "Code",
}
but I expect somethings like this :
{
"PROD_Name": "Name",
"PROD_Code": "Code",
}
Simply equal to my attributes names in my entity, I don't understand why first letter get lowercase and my underscore get out...
Thanks for your help !