Symfony Serializer
Converts PHP objects to JSON, XML, CSV, and YAML and back again
Repository Health
Technical Analysis
Symfony Serializer handles the two-way transformation between PHP object graphs and array/string representations like JSON, XML, CSV, and YAML. It splits the job into normalizers (object <-> array) and encoders (array <-> string format), so each concern can be swapped or extended independently — you can write a custom normalizer for a specific class without touching how JSON gets encoded.
Beyond basic (de)serialization, it supports attribute-based configuration (#[Groups], #[SerializedName], #[Context]), circular reference handling, denormalization into typed objects using constructor promotion and property types, and integrates with Symfony’s Validator and PropertyInfo components for schema-aware mapping. It’s the serialization layer used throughout Symfony’s HttpFoundation/HttpKernel stack for API request/response bodies.
What You Get
- A pluggable
Serializercombining normalizers (object <-> array) and encoders (array <-> string format: JSON, XML, CSV, YAML) - PHP attributes for per-property control:
#[Groups],#[SerializedName],#[SerializedPath],#[Ignore],#[Context] ObjectNormalizerthat uses reflection plus PropertyInfo/PropertyAccess to (de)normalize arbitrary classes without manual mapping- Built-in normalizers for common types:
DateTimeNormalizer,DateIntervalNormalizer,BackedEnumNormalizer,UidNormalizer,ConstraintViolationListNormalizer - Circular reference and object-graph depth handling to avoid infinite loops when serializing nested/related entities
Common Use Cases
- Converting API request bodies (JSON) into typed DTOs/entities and validating them, and converting response entities back to JSON
- Exporting application data to CSV or YAML for reports, imports, or configuration files
- Building framework-agnostic API layers that need consistent, attribute-driven control over which fields serialize under which “group” (e.g. public vs. admin views)
- Denormalizing third-party API responses into internal PHP value objects with strict typing
Under The Hood
Architecture - The Serializer class (413 lines) is a thin coordinator: it iterates a configured list of normalizer/encoder services, asking each supportsNormalization()/supportsEncoding() in turn and delegating to the first match. Heavy lifting lives in AbstractObjectNormalizer, which uses symfony/property-info and reflection to map object properties to array keys and back, and in the Encoder/ directory (JsonEncoder, XmlEncoder, CsvEncoder, YamlEncoder) which handle only format-level concerns.
Tech Stack - Pure PHP 8.4+ core with a required-only dependency on deprecation-contracts and ctype polyfill; nearly two dozen optional dev/peer integrations (Validator, PropertyAccess, PropertyInfo, TypeInfo, Cache, Console, DependencyInjection, Messenger, Uid, VarExporter) light up extra normalizers and Symfony DI wiring when present.
Code Quality - Extensive test suite under Tests/ with dedicated test classes per normalizer/encoder plus integration tests like DeserializeNestedArrayOfObjectsTest; the Attribute/ directory shows disciplined use of typed PHP attributes rather than annotations. Exception classes are specific (NotEncodableValueException, CircularReferenceException, ExtraAttributesException) enabling precise error handling by callers.
API Design - The public API centers on two calls, serialize()/deserialize(), with behavior tuned via a $context array and attributes rather than constructor arguments, keeping the surface small while still exposing deep configurability (groups, circular reference handlers, max depth) for complex object graphs.
Used by 4 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Hyvor Relay
Devops · AI Development · Monitoring
Self-hosted, open-source email API that automates DNS, manages SMTP delivery, and provides deep observability — replacing SES, Mailgun, and SendGrid with infrastructure you fully own.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.