In my Symfony 3 web app I'm serializing some DB rows into Json as follows:
$doc = $this->get ( 'doctrine' );
$repo = $doc->getRepository ( 'AppBundle:Customer' );
$result = $repo->createQueryBuilder ( 'c' )->setMaxResults(25)->getQuery ()->getResult ();
$encoder = new JsonEncoder ();
$normalizer = new GetSetMethodNormalizer ();
$serializer = new Serializer ( array (
new \AppBundle\DateTimeNormalizer(), $normalizer
), array (
$encoder
) );
$json = $serializer->serialize ( $result, 'json' );
This outputs the desired data, e.g:
{companyname:"Microsoft"}
In order to (at least initially) maintain compatibility with a legacy system, I'd like all the Json names to be in uppercase, e.g.
{COMPANYNAME:"Microsoft"}
Is the best way to tackle this by approaching from:
- The Encoder
- The Normalizer(s)
- The Serializer
- Some other way?
Please briefly describe the suggested approach