two types of documents on the Symfony.com 1. The Symfony Component 2. How to use the Symfony Component in the Symfony Framework • If you use another framework, you should read the above 1 instead of 2
Symfony\Component\Serializer\Annotation\SerializedName; final class Cat { // snip #[Groups('list')] #[SerializedName('lower_name')] public function getLowerCaseName(): string { return mb_strtolower($this->getName()); } // snip src/Model/v105/Cat.php
• "Denormalizer" only effects to the process of denormalize Object Format (JSON, XML, CSV) Array serialize deserialize normalize denormalize encode decode
Platform uses the Symfony Serializer • They implement some useful custom Encoders for API: • JSON-LD, GraphQL, OpenAPI, HAL, JSON:API, and so on • See also: https://api-platform.com/
$context = []): string return $this->encoder->encode($data, $format, $context); if ($this->encoder->supportsEncoding($format, $context)) if ($this->encoder->needsNormalization($format, $context)) { $data = $this->normalize($data, $format, $context); } throw new Exception No $normalizers [Note] These codes are not real, it's image
$format, array $context = []): mixed return $this->denormalize($data, $type, $format, $context); if ($this->encoder->supportsDecoding($format, $context)) $this->decoder->decode($data, $format, $context); throw new Exception No $normalizers [Note] These codes are not real, it's image
knows its own supported format • It receives its own supported context • Each Normalizer • It knows its own supported format and data • It receives its own supported context • Serializer • It choices Encoder by format • It choices Normalizer by format and data
only controls Normalizers and Encoders • Splitting Normalizer and Encoder is a good idea • Splitting NormalizeInterface and DenormalizeInterface, too • Splitting EncoderInterface and DecorderInterface, too