JMSSerializerBundle
Symfony integration bundle for JMS Serializer, wiring configurable JSON/XML/YAML (de)serialization into the framework's DI container
Repository Health
Technical Analysis
JMSSerializerBundle integrates the standalone jms/serializer library into Symfony applications, exposing its powerful, annotation/attribute-driven serialization engine as a configured service inside the framework’s dependency-injection container. It handles arbitrarily complex object graphs — nested objects, collections, polymorphic types, virtual properties — and serializes them to JSON, XML, or YAML with fine-grained control over property exposure, versioning, and grouping.
The bundle predates Symfony’s own Serializer component and remains widely used where teams need capabilities the core component doesn’t offer as directly, such as expression-language-based property exclusion, deep customization of (de)serialization contexts, and long-standing annotation-based metadata that many legacy Symfony codebases already depend on.
What You Get
- Symfony DI integration for
jms/serializer, configurable viaconfig/packages/jms_serializer.yaml - Annotation and PHP-attribute based mapping for exclusion strategies, groups, versions, and virtual properties
- Serialization to JSON, XML, and YAML from the same object metadata
- Doctrine integration for lazy-loading proxies and entity metadata during serialization
- Symfony ExpressionLanguage support for conditional property exclusion rules
Common Use Cases
- Serializing complex Doctrine entity graphs (nested relations, collections) to API JSON responses with fine-grained field control
- Supporting multiple API versions from one set of models via version-based property exclusion groups
- Migrating legacy Symfony 2/3 applications that already depend on JMS annotations without a full serializer rewrite
- Producing XML or YAML representations of the same domain objects alongside JSON for interoperability with older clients
Under The Hood
Architecture JMSSerializerBundle.php and DependencyInjection/ register the standalone jms/serializer library’s SerializerBuilder as Symfony services, exposing its metadata-driven serialization pipeline (annotation/attribute readers → metadata factory → format-specific visitors) through the framework’s config tree; ContextFactory/ builds per-request serialization/deserialization contexts, and Serializer/ adds Symfony-specific handlers (e.g. Doctrine proxy unwrapping, form error serialization via Templating/).
Tech Stack PHP bundle requiring jms/serializer ^3.31 and jms/metadata ^2.6 as the core engine, layered onto Symfony 5.4–8.0 (framework-bundle, dependency-injection, config); optional dev dependencies include Doctrine ORM and Symfony ExpressionLanguage/Form for extended integration.
Code Quality A dedicated Tests/ tree with PHPUnit covers the DI extension, context factory, and serializer handlers; CHANGELOG.md and UPGRADING.md document breaking changes across major versions, consistent with a long-lived, widely-depended-on Symfony ecosystem bundle.
API Design Configuration happens through Symfony’s standard bundle config (config/packages/jms_serializer.yaml) plus per-property annotations/attributes on model classes, which is idiomatic for Symfony but requires learning JMS’s specific annotation vocabulary (@Exclude, @Groups, @Since/@Until) — a moderate learning curve, especially for teams coming from Symfony’s own Serializer component with different attribute names.
Used by 3 apps in this directory
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.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.