jms-serializer/serializer
JMS Serializer is a mature PHP library for converting objects to and from JSON, XML, YAML, and other formats. It offers configurable metadata, annotations or attributes, handlers, and visitors for complex serialization needs.
toArray()/fromArray() mappers, ad-hoc array shaping, and bespoke hydrators with metadata-driven configuration. The buy case is strongest where DTO count is high and field-level rules (renames, date formats, nested objects, conditional exposure) keep changing.Adopt when:
Look elsewhere when:
spatie/laravel-data onboard faster and are better documented for this stack.jms-serializer/serializer does not match the canonical Composer package jms/serializer (zero stars, zero dependents). A near-name variant is a classic dependency-confusion vector and must be verified against upstream before any adoption decision — this gate supersedes all other criteria.For executives. We have a recurring, unbudgeted cost: every new integration or API format gets a bespoke mapping and transformer layer, then a permanent maintenance tail. This package replaces that with one declarative configuration, letting a single model serve JSON, XML, and YAML. The commercial unlock is the B2B/partner pipeline that requires XML — currently scoped as a separate build. The buy decision removes that line item from the roadmap and makes future format requests incremental rather than new projects. Risk is contained: it sits behind an internal interface at the edge of the system, so it is replaceable if it disappoints, and its blast radius is bounded to integrations rather than core domain logic. One caveat: we must confirm we are adopting the canonical upstream package, not a lookalike name — a fast provenance check before the pilot.
For engineering. It is a mature, framework-agnostic serializer with explicit metadata mapping, serialization groups for versioning, custom visitors for new formats, and strong deserialization support for third-party payloads. The trade-offs are honest: it is not Laravel-native, so we own a service-provider binding, a metadata-cache warmup step, and a wrapper that keeps every service from re-inventing configuration; annotation/attribute style differs from what most of the team writes day to day; and it is heavier than API Resources for trivial JSON. Deserialization of untrusted input needs a security review (XXE, type coercion, gadget chains), and XML entity loading must be explicitly disabled. If our model is mostly flat CRUD, this is over-engineering and we should say so. If we expect nested, multi-format, versioned payloads — which the roadmap suggests — this is the right foundation, and it lets us delete mapping code rather than add it. Sequence the work as: provenance check → one-week spike → ADR defining the boundary ("JMS owns external contracts, Laravel owns internal serialization") → wrapper + pilot → expand only where the ADR's criteria are met.
How can I help you explore Laravel packages today?