Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Serializer Bundle

Serializer Bundle Laravel Package

anzusystems/serializer-bundle

AnzuSerializer is a fast, lightweight Symfony serializer bundle. Inject the Serializer to turn DTOs into JSON and deserialize JSON into objects or collections. Configure via attributes: custom DateTime formats, enums, Uuid, value objects, entity ID handlers, and more.

View on GitHub
Deep Wiki
Context7

AnzuSerializer is a fast, lightweight serialization bundle for Symfony that converts objects and iterables to JSON and back. Inject AnzuSystems\SerializerBundle\Serializer and use serialize() or deserialize() to handle single DTOs, arrays, or collections.

Control behavior with the #[Serialize] attribute on properties or methods, letting you fine-tune types, formats, and handlers.

  • Configurable date format for DateTimeInterface
  • Automatic handling of value objects, enums, and UUIDs
  • Discriminator maps for polymorphic deserialization
  • Entity ID handlers for serializing collections as IDs
  • Collection/array type hints for nested DTOs
Frequently asked questions about Serializer Bundle
Is anzusystems/serializer-bundle compatible with Laravel?
anzusystems/serializer-bundle is a Symfony serializer bundle rather than a Laravel-native package, so Laravel integration means wiring it through Symfony's dependency injection and configuration. The provided technical assessment rates Laravel 10.x and 11.x as likely compatible because they use Symfony 6.4+, while Laravel 9.x is risky if the bundle pulls Symfony 8 dependencies. Check composer.json constraints and test the exact Laravel and Symfony combination before adopting it.
How do I install anzusystems/serializer-bundle?
Run composer require anzusystems/serializer-bundle and make sure your Laravel app's Symfony components satisfy the bundle's constraints. In Symfony you enable the bundle and use config/packages/anzu_systems_serializer.yaml; in Laravel expect to register the serializer service and provide equivalent config manually because bundle auto-discovery is not guaranteed. Then inject AnzuSystems\SerializerBundle\Serializer where needed.
What PHP attributes do I need on DTO properties to serialize them?
Add the #[Serialize] attribute to each property or method you want the serializer to read or write. Options include type for iterables and custom date formats, handler with EntityIdHandler for entity-ID collections, and discriminatorMap for polymorphic deserialization. Value objects must implement ValueObjectInterface, enums must implement EnumInterface, and UUIDs must be Symfony Uid Uuid instances.
How do I serialize and deserialize collections or arrays of DTOs?
For array or Collection properties, set type: DummyDto::class on the #[Serialize] attribute so the serializer knows how to deserialize each item. Deserialization can return an array or a collection by passing the target class and, if needed, a Collection instance such as ArrayCollection. For entity collections that should serialize as ordered IDs, use EntityIdHandler with orderBy criteria.
How do I change the default date format for DateTime serialization?
Set anzu_systems_serializer.date_format in the bundle configuration, for example config/packages/anzu_systems_serializer.yaml in Symfony or the equivalent config location in your Laravel wiring. The default format shown is Y-m-d\TH:i:s.u\Z. Override a single property with #[Serialize(type: 'd.m.Y H:i:s')] when only that field needs a different format.
What is the configurable class metadata cache pool added in 6.3.0?
Release 6.3.0 makes the class metadata cache pool configurable, so teams can choose where serializer metadata is stored instead of being locked to the bundle default. The pool is expected to satisfy the cache interface the bundle requires, likely PSR-6 CacheItemPoolInterface, so Laravel may need a thin adapter over its Cache facade or use symfony/cache. If you use a shared or persistent pool, invalidate or version it after DTO, normalizer, or serializer metadata changes to avoid stale metadata.
Which Laravel and Symfony versions does the 6.x line support?
The assessment says the 6.x line continues to target Symfony 8, which can be a breaking constraint, and only 6.3.0 was evaluated in detail. Laravel 10.x and 11.x are likely compatible with Symfony 6.4+, but Laravel 9.x is risky. Read the 6.1.x and 6.2.x changelogs and check composer.json for exact minimums, then pin Symfony dependencies in your project.
How should I test this serializer in a Laravel application?
Write unit or feature tests that serialize and deserialize representative DTOs, including nested DTOs, dates with custom formats, enums, UUIDs, value objects, arrays, and Collections. Assert both the JSON shape and round-trip behavior. If you use a shared metadata cache pool, add tests for cache invalidation after DTO changes, and test against the Symfony version your Laravel app actually installs.
Are there production risks with caching serializer metadata in Redis or the database?
Yes, a shared or persistent metadata cache introduces a staleness surface. After a deploy that changes DTOs, normalizers, or serializer metadata, the cache must be invalidated or versioned or the app may serialize against outdated metadata. The no-config default is likely an in-process array, which avoids cross-node staleness but is per-process; choose a pool deliberately and add cache invalidation to your deploy pipeline.
What alternatives exist for serializing DTOs in Laravel?
Common alternatives include using Laravel's JSON resources and responses directly, using symfony/serializer without this bundle, spatie/laravel-data, or fractal for transformation layers. This bundle is a good fit when you want attribute-driven Symfony-style serialization with handlers for entity IDs, value objects, enums, and UUIDs in a small footprint. Compare it against Laravel-native validation, resource, and cache-control needs before standardizing on it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels