PHPackages                             wayofdev/laravel-symfony-serializer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. wayofdev/laravel-symfony-serializer

ActiveLibrary[API Development](/categories/api)

wayofdev/laravel-symfony-serializer
===================================

📦 Laravel wrapper around Symfony Serializer.

v3.0.0(1y ago)2113.6k—8.4%3[1 issues](https://github.com/wayofdev/laravel-symfony-serializer/issues)[10 PRs](https://github.com/wayofdev/laravel-symfony-serializer/pulls)MITPHPPHP ^8.2CI passing

Since Jun 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/wayofdev/laravel-symfony-serializer)[ Packagist](https://packagist.org/packages/wayofdev/laravel-symfony-serializer)[ Docs](https://wayof.dev)[ GitHub Sponsors](https://github.com/wayofdev)[ RSS](/packages/wayofdev-laravel-symfony-serializer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (25)Versions (110)Used By (0)

 [   ![WayOfDev Logo](https://raw.githubusercontent.com/wayofdev/.github/master/assets/logo.gh-light-mode-only.png)  ](https://wayof.dev)

 **Build**
 [![Build Status](https://camo.githubusercontent.com/2fa16ff9d710fa0c3b42bb3c747b7ed36effaf6b2eb2a277530a5e1b9fd5b439/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246616374696f6e732d62616467652e6174726f782e6465762532467761796f666465762532466c61726176656c2d73796d666f6e792d73657269616c697a65722532466261646765267374796c653d666c61742d737175617265266c6162656c3d676974687562253230616374696f6e73)](https://github.com/wayofdev/laravel-symfony-serializer/actions)

 **Project**
 [![Total Downloads](https://camo.githubusercontent.com/591613edfc0963d6e0518cc07c9370f2e5206e47683652b90f8246a5c9734258/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7761796f666465762f6c61726176656c2d73796d666f6e792d73657269616c697a65723f267374796c653d666c61742d737175617265)](https://packagist.org/packages/wayofdev/laravel-symfony-serializer) [![Latest Stable Version](https://camo.githubusercontent.com/0359d95730e4268361230f80c2b35a2af85f66ac22b75cea5e7cd67d28157556/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7761796f666465762f6c61726176656c2d73796d666f6e792d73657269616c697a65723f267374796c653d666c61742d737175617265)](https://packagist.org/packages/wayofdev/laravel-symfony-serializer) [![Commits since latest release](https://camo.githubusercontent.com/223c69654f4accc2fe0e2d96f29375036591f27e78c37fe4e47886356dc8d4ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f7761796f666465762f6c61726176656c2d73796d666f6e792d73657269616c697a65722f6c61746573743f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wayofdev/laravel-symfony-serializer) [![PHP Version Require](https://camo.githubusercontent.com/96731e3b40204d298905bf01ca6f28c8dd8677ef796084fb894b192575f30cb9/68747470733a2f2f706f7365722e707567782e6f72672f7761796f666465762f6c61726176656c2d73796d666f6e792d73657269616c697a65722f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wayofdev/laravel-symfony-serializer)

 **Quality**
 [![Codecov](https://camo.githubusercontent.com/f60a28031ce8b62480fc52808b8c16a211efe5e50818a57d3600dd8ab967924e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7761796f666465762f6c61726176656c2d73796d666f6e792d73657269616c697a65723f7374796c653d666c61742d737175617265266c6f676f3d636f6465636f76)](https://app.codecov.io/gh/wayofdev/laravel-symfony-serializer) [![Mutation testing badge](https://camo.githubusercontent.com/c8afc8a873f2a318b4f0b90b587c1a6986b94d795d8ef4512813dc479f6fa4ef/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742d737175617265266c6162656c3d6d75746174696f6e25323073636f72652675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532467761796f666465762532466c61726176656c2d73796d666f6e792d73657269616c697a65722532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/wayofdev/laravel-symfony-serializer/master) ![PHP Stan Level 6 of 9](https://camo.githubusercontent.com/beb41442cb07995c2058dee0712dc6da395460de80c153d3f46aa1fe48c2d935/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2532306c6576656c2d382532306f66253230392d627269676874677265656e3f7374796c653d666c61742d737175617265)

 **Community**
 [![Discord](https://camo.githubusercontent.com/34f37f68c2881c391251fb943c5110653c5e3d1076af732b7830211aff4f616b/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f313232383530363735383536323035383339313f7374796c653d666c61742d737175617265266c6f676f3d646973636f7264266c6162656c436f6c6f723d373238396439266c6f676f436f6c6f723d776869746526636f6c6f723d333934353664)](https://discord.gg/CE3TcCC5vr) [![Follow on Twitter (X)](https://camo.githubusercontent.com/91c1c3b545d03e0c79f91364259b2814308d2b3786c67c8578740879528ff37c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d466f6c6c6f772d626c61636b3f7374796c653d666c61742d737175617265266c6f676f3d58)](https://x.com/intent/follow?screen_name=wayofdev)

Laravel Symfony Serializer
==========================

[](#laravel-symfony-serializer)

This package integrates the Symfony Serializer component into Laravel, providing a powerful tool for serializing and deserializing objects into various formats such as JSON, XML, CSV, and YAML.

Detailed documentation on the Symfony Serializer can be found on their [official page](https://symfony.com/doc/current/components/serializer.html).

🗂️ Table of Contents
--------------------

[](#️-table-of-contents)

- [Purpose](#-purpose)
- [Installation](#-installation)
- [Configuration](#-configuration)
    - [Configuration Options](#-configuration-options)
    - [Custom Strategies](#-custom-strategies)
- [Usage](#-usage)
    - [Components](#-components)
    - [Example DTO](#-example-dto)
    - [Using `SerializerManager` in your Service Classes](#-using-serializermanager-in-service-classes)
    - [Using `ResponseFactory` in Laravel Controllers](#-using-responsefactory-in-laravel-controllers)
    - [Using in Laravel Queues](#-using-in-laravel-queues)
- [Security Policy](#-security-policy)
- [Want to Contribute?](#-want-to-contribute)
- [Contributors](#-contributors)
- [Social Links](#-social-links)
- [License](#-license)
- [Credits and Useful Resources](#-credits-and-useful-resources)

🤔 Purpose
---------

[](#-purpose)

This package brings the power of the Symfony Serializer component to Laravel. While Laravel does not have a built-in serializer and typically relies on array or JSON transformations, this package provides more advanced serialization capabilities. These include object normalization, handling of circular references, property grouping, and format-specific encoders.

If you are building a REST API, working with queues, or have complex serialization needs, this package will be especially useful. It allows you to use objects as payloads instead of simple arrays and supports various formats such as JSON, XML, CSV, and YAML. This documentation will guide you through the installation process and provide examples of how to use the package to serialize and deserialize your objects.

🙏 If you find this repository useful, please consider giving it a ⭐️. Thank you!

💿 Installation
--------------

[](#-installation)

Require the package as a dependency:

```
composer require wayofdev/laravel-symfony-serializer
```

You can publish the config file with:

```
$ php artisan vendor:publish \
  --provider="WayOfDev\Serializer\Bridge\Laravel\Providers\SerializerServiceProvider" \
  --tag="config"
```

🔧 Configuration
---------------

[](#-configuration)

The package configuration file allows you to customize various aspects of the serialization process.

Below is the default configuration provided by the package:

```
