×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Jorge Alcalá
Added: Dec 3, 2021 7:29 PM
Views: 937
Tags: no tags
  1. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  2. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  3. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  4. use Symfony\Component\Serializer\Serializer;
  5.  
  6.         $encoders = [new XmlEncoder(), new JsonEncoder()];
  7.         $normalizers = [new ObjectNormalizer()];
  8.  
  9.         $serializer = new Serializer($normalizers, $encoders);
  10.        
  11.         $vehiculoJSON = $serializer->serialize($vehiculo, 'json');