$encoders = [new XmlEncoder(), new JsonEncoder()];
$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/var/www/new-sys.local/config/packages/serialization/definition.xml'));
$defaultContext = [
AbstractObjectNormalizer::MAX_DEPTH_HANDLER => function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
return $innerObject->id;
},
AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => function ($object, $format, $context) {
return $object->getId();
},
];
$normalizers = [
new DateTimeNormalizer(),
new ObjectNormalizer(
$classMetadataFactory,
null,
null,
null,
null,
null,
$defaultContext
),
];
$serializer = new Serializer($normalizers, $encoders);
$tickets = $this->em->getRepository(Ticket::class)->findBy([], null, 10);
$jsonContent = $serializer->serialize($tickets, 'json', [
AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true,
]);
И может знает кто хороший пример работы api проекта на симфони с использованием symfony/serializator?