PHPackages                             edudobay/doctrine-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. [Database &amp; ORM](/categories/database)
4. /
5. edudobay/doctrine-symfony-serializer

ActiveLibrary[Database &amp; ORM](/categories/database)

edudobay/doctrine-symfony-serializer
====================================

Map fields in Doctrine ORM using Symfony Serializer

0.5.0(1mo ago)47.2k—0%1MITPHPPHP ^8.0CI passing

Since Dec 16Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/edudobay/doctrine-symfony-serializer)[ Packagist](https://packagist.org/packages/edudobay/doctrine-symfony-serializer)[ Docs](https://github.com/edudobay/doctrine-symfony-serializer)[ RSS](/packages/edudobay-doctrine-symfony-serializer/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (15)Versions (12)Used By (0)

Mapping fields in Doctrine ORM using Symfony Serializer
=======================================================

[](#mapping-fields-in-doctrine-orm-using-symfony-serializer)

[![Version](https://camo.githubusercontent.com/aafe558c18566b24bde941aebd68c19ffc2385b4dafab8a5b51a691e8f6e9c9d/687474703a2f2f706f7365722e707567782e6f72672f656475646f6261792f646f637472696e652d73796d666f6e792d73657269616c697a65722f76657273696f6e)](https://packagist.org/packages/edudobay/doctrine-symfony-serializer)[![License](https://camo.githubusercontent.com/940560488c5723aad8f2b687470731692828dc721d0547fd3570bbcaf5b8317e/687474703a2f2f706f7365722e707567782e6f72672f656475646f6261792f646f637472696e652d73796d666f6e792d73657269616c697a65722f6c6963656e7365)](https://packagist.org/packages/edudobay/doctrine-symfony-serializer)

This is a proof of concept for a mapping fields with [Doctrine ORM](https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/index.html) so they can be serialized with the [Symfony Serializer component](https://symfony.com/doc/current/components/serializer.html), without the need to create a mapping type for each possible data type.

Sometimes you just need to store a complex data type (generally a [Value Object](https://martinfowler.com/bliki/ValueObject.html)) in a JSON field and not worry about database schemas, extra columns or tables, [Doctrine embeddables](https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/tutorials/embeddables.html), [custom mappings](https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/cookbook/custom-mapping-types.html).

Installation
------------

[](#installation)

This library requires PHP 8.0 or later.

```
composer require edudobay/doctrine-symfony-serializer

```

Usage
-----

[](#usage)

See the [examples](./examples/main.php) directory for a working code example.

### Abridged example

[](#abridged-example)

Add this to your application setup:

```
use Edudobay\DoctrineSerializable\ReflectionClassMetadataFactory;
use Edudobay\DoctrineSerializable\SerializationHandler;
use Edudobay\DoctrineSerializable\PersistenceEventSubscriber;

$serializer = ...; // Symfony Serializer
$entityManager = ...; // Doctrine ORM EntityManager

$subscriber = new PersistenceEventSubscriber(new SerializationHandler(
    $serializer,
    // You might want to cache this. See Psr6CacheClassMetadataFactory
    new ReflectionClassMetadataFactory()
));

$entityManager->getEventManager()->addEventSubscriber($subscriber);
```

In your entities, have your domain object as you like, and introduce a private backing field that will make it persistent:

```
use Doctrine\ORM\Mapping as ORM;
use Edudobay\DoctrineSerializable\Attributes\Serializable;

#[ORM\Entity]
class User
{
    // Backing field
    #[ORM\Column('address', type: 'json')]
    private array $_address = [];
    // The actual domain object
    #[Serializable]
    public Address $address;

    // For arrays:
    #[ORM\Column('badges', type: 'json')]
    private array $_badges = [];

    #[Serializable]
    /** @var Badge[] */
    public array $badges;

    // OPTIONAL: use arrayItemType instead of docblock array types
    #[Serializable(arrayItemType: Badge::class)]
    public array $badges;
}
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~152 days

Recently: every ~370 days

Total

11

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5598663764fcc0e7ebf0a1cbfe111f369fc51f0559c5b2931e4fb7070192e91e?d=identicon)[edudobay](/maintainers/edudobay)

---

Top Contributors

[![edudobay](https://avatars.githubusercontent.com/u/4432091?v=4)](https://github.com/edudobay "edudobay (43 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/edudobay-doctrine-symfony-serializer/health.svg)

```
[![Health](https://phpackages.com/badges/edudobay-doctrine-symfony-serializer/health.svg)](https://phpackages.com/packages/edudobay-doctrine-symfony-serializer)
```

###  Alternatives

[dunglas/doctrine-json-odm

An object document mapper for Doctrine ORM using JSON types of modern RDBMS.

6254.8M7](/packages/dunglas-doctrine-json-odm)[doctrine/doctrine-orm-module

Laminas Module that provides Doctrine ORM functionality

4407.2M276](/packages/doctrine-doctrine-orm-module)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

645963.8k](/packages/sonata-project-entity-audit-bundle)[williarin/wordpress-interop

Interoperability library to work with WordPress database in third party apps

6610.8k1](/packages/williarin-wordpress-interop)[goodwix/doctrine-json-odm

JSON Object-Document Mapping bundle for Symfony and Doctrine

2225.6k](/packages/goodwix-doctrine-json-odm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
