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.
#[Serialize], serializedName, discriminatorMap) become the single source of truth for the wire format. Combined with the auto-registered NelmioApiDocBundle describer, OpenAPI docs are generated from the same metadata that does the (de)serialization — that is a documentation-drift decision, not a code decision. If your roadmap includes public/partner-facing API docs, this materially reduces the support burden of stale specs.EntityIdHandler lets you emit author: 42 instead of embedding a full Author object, and hydrate back to an entity on input. That is a product-level API shape decision (IDs vs. nested expansion) that directly affects payload size, mobile/bandwidth budgets, and how much a client must know about your graph.discriminatorMap supports heterogeneous collections in a single endpoint (e.g. a feed of person and machine items). Useful if the roadmap includes mixed-type timelines, activity feeds, or extensible content blocks; otherwise it's unused surface.BatchSerializeHandlerInterface / BatchDeserializeHandlerInterface) collapse per-item lookups into one query per collection. For list endpoints backed by Doctrine relations this is the difference between a 40ms and a 1.2s response — a concrete way to hit a latency SLO without adding a caching tier.readonly/immutable DTOs and toward mutable, setter-driven models. That's an architecture decision your tech lead should own, not something to discover mid-sprint.Reasonable fit when most of these are true:
EntityIdHandler and batch handlers exist precisely to solve the ID-vs-object and N+1 problems, and they're the main reason to prefer this over Symfony's native Serializer.Look elsewhere when any of these are true:
For executives: This is a small, free (Apache-2.0) Symfony component that replaces hand-written JSON conversion code and, in doing so, eliminates two recurring costs: API documentation that drifts out of sync with the API, and slow list endpoints caused by per-item database lookups. The trade-off is vendor concentration — it's maintained by a single organization with no external user base — so adoption should be treated as a build-vs-buy bet with a defined exit path, not a default.
For engineering: It's attribute-driven, Doctrine-aware, and the batch handler interfaces solve the N+1-on-serialization problem that Symfony's native Serializer leaves to you. The Nelmio integration gives you OpenAPI for free. The costs are real and specific: JSON only, public getter/setter plus no-required-constructor on every serialized class, and batch semantics with enough caveats (array/Collection only, forced handlers only, idempotency required, singleton state in long-running workers) that they need a test before you rely on them. Pin the version, keep the serializer attributes off your domain entities and on a DTO layer so the dependency stays swappable, and benchmark against Symfony Serializer on a representative list endpoint before committing. If it doesn't win on that benchmark, the only remaining argument is the OpenAPI generation — which is worth having, but not worth a one-way dependency.
How can I help you explore Laravel packages today?