PHPackages                             webit/doctrine-jms-json - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. webit/doctrine-jms-json

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

webit/doctrine-jms-json
=======================

Converts complex objects using JMS Serializer

4.0.1(6mo ago)652.7k↓50%6[1 PRs](https://github.com/dbojdo/Doctrine-JMS-JSON/pulls)1MITPHPPHP &gt;=8.1

Since Aug 29Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/dbojdo/Doctrine-JMS-JSON)[ Packagist](https://packagist.org/packages/webit/doctrine-jms-json)[ RSS](/packages/webit-doctrine-jms-json/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (14)Used By (1)

Doctrine JMS Json Type
======================

[](#doctrine-jms-json-type)

Persist your Value Objects with Doctrine using JMS Serializer. The DBAL Type supports anything that can be handled by JMS Serializer (scalar, array, Doctrine Collections, DateTime, etc).

Installation
============

[](#installation)

Add ***"webit/doctrine-jms-json": "^2.0.0"*** to the require section of your ***composer.json***

```
{
    "require": {
        "webit/doctrine-jms-json": "^3.0.0"
    }
}
```

Usage
=====

[](#usage)

Configure register new Doctrine DBAL type and configure the Serializer:

```
# boostrap.php

use Doctrine\DBAL\Types\Type;
use Webit\DoctrineJmsJson\DBAL\JmsJsonType;
use JMS\Serializer\SerializerBuilder;
use Webit\DoctrineJmsJson\Serializer\Type\DefaultSerializerTypeResolver;

Type::addType('jms_json', 'Webit\DoctrineJmsJson\DBAL\JmsJsonType');

$serializer = SerializerBuilder::create()->build();
// initialize JmsJsonType
JmsJsonType::initialize($serializer, new DefaultSerializerTypeResolver());
```

Now you can use "jms\_json" in the Doctrine field mapping as a type.

See full configuration of JMS Serializer [here](http://jmsyst.com/libs/serializer)See full documentation of Doctrine Mapping [here](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping)See Doctrine Custom Types documentation [here](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html)

Example
=======

[](#example)

"jms\_json" DBAL type can be very useful to store [Value Objects](https://en.wikipedia.org/wiki/Value_object) or objects that structures may vary.

Consider example of a **slider** on a web page. Let class ***BannerSet*** contain the ***Slider*** configuration.

```
interface Slider
{
}

class BannerSet
{
    private $id;

    /** Slider */
    private $slider;

    /**
     * @return Slider
     */
    public function slider()
    {
        return $this->slider;
    }

    /**
     * @param Slider $slider
     */
    public function changeSlider(Slider $slider)
    {
        $this->slider = $slider;
    }
}
```

There are plenty of different JavaScript slider configurations so we don't know in advance the Slider structure. Let's introduce two implementations:

```
use JMS\Serializer\Annotation as JMS;

class Slider1 implements Slider
{
    /**
     * @JMS\Type("string")
     */
    private $theme;

    /**
     * @JMS\Type("double")
     */
    private $slideTime;

    // ...
}

class Slider2 implements Slider
{
    /**
     * @JMS\Type("array")
     */
    private $effects;

    /**
     * @JMS\Type("boolean")
     */
    private $stopOnHover;

    /**
     * @JMS\Type("integer")
     */
    private $pauseTime;

    // ...
}

```

To persist the ***BannerSet*** in the database using Doctrine ORM we need to provide the mapping. Using the standard relational approach we need to map ***BannerSet*** and every ***Slider*** (probably using \[single table inheritance\]). It means, we'll have two tables in the database "banner\_set" and "slider" with one-to-one relationship between them - quite complex for storing slider configuration. The more, this approach requires to store ***Slider*** instances like Entities (we have to introduce ID to store in the table), what breaks our model.

Slider configuration is just object we need to store, but we don't need to query for it. So it's much simpler to store it in a JSON format in one column of "banner\_set" table.

***BannerSet*** Doctrine mapping file would look like:

```
entity:
    class: BannerSet
    id:
        id:
            type: int
    fields:
        slider:
            type: jms_json
```

And that's it!

Obviously, we need to provide the ***Serializer*** mapping for ***Slider1*** and ***Slider2***(what can be done in different ways, eg. via Annotations - check the [JMSSerializer documentation](http://jmsyst.com/libs/serializer) for more details).

Symfony 2/3 integration
=======================

[](#symfony-23-integration)

See [WebitDoctrineJsonBundle](https://github.com/dbojdo/Doctrine-JSON-Bundle) Symfony 2/3 integration.

Tests
=====

[](#tests)

```
composer install
./vendor/bin/phpunit

```

Change log
==========

[](#change-log)

Version 2.0.0
-------------

[](#version-200)

Introduces support for native JSON type database field. Internally data are stored in a valid JSON format ('{"\_jms\_type": "Deserialisation Type", "data": "DATA TO BE DESERIALISED"}'). This breaks backwards compatibility with version **1.x**. Version **1.x** cannot be upgraded to **2.x** without manual conversion of the saved data.

Version 2.1.0
-------------

[](#version-210)

Provides backwards compatibility with version **1.x** on conversion to PHP Value (reading from the database). Please note, the data read from the format of version **1.x** will be converted automatically to the new format during flush process of the entity.

Version 3.0.0
-------------

[](#version-300)

Provides support for higher JMS Serializer versions (2.x, 3.x). This version required PHP &gt;= 7.2.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance68

Regular maintenance activity

Popularity35

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~280 days

Recently: every ~481 days

Total

13

Last Release

189d ago

Major Versions

1.0.1 → 2.0.02019-11-11

2.x-dev → 3.0.02020-03-23

3.1.1 → 4.0.02025-11-10

PHP version history (3 changes)1.0.0PHP &gt;=5.3.2

3.0.0PHP &gt;=7.2

4.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a6cc50814a7b150c2a02d719d33c6e11040a6d0d010b2f986a24794edce7f52f?d=identicon)[dbojdo](/maintainers/dbojdo)

---

Top Contributors

[![cjprinse-etrias](https://avatars.githubusercontent.com/u/26894139?v=4)](https://github.com/cjprinse-etrias "cjprinse-etrias (2 commits)")[![cjprinse](https://avatars.githubusercontent.com/u/9368015?v=4)](https://github.com/cjprinse "cjprinse (1 commits)")[![Mika56](https://avatars.githubusercontent.com/u/600347?v=4)](https://github.com/Mika56 "Mika56 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webit-doctrine-jms-json/health.svg)

```
[![Health](https://phpackages.com/badges/webit-doctrine-jms-json/health.svg)](https://phpackages.com/packages/webit-doctrine-jms-json)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[easybill/zugferd-php

ZUGFeRD PHP SDK (Factur-X, XRechnung) - Convert PHP Objects to XML and back.

99295.7k8](/packages/easybill-zugferd-php)[oat-sa/tao-core

TAO core extension

66136.7k74](/packages/oat-sa-tao-core)[jansenfelipe/nfephp-serialize

Transforme NFe(xml) em objetos PHP (e vice-versa)

714.4k](/packages/jansenfelipe-nfephp-serialize)

PHPackages © 2026

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