PHPackages                             serialization/serialization - 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. serialization/serialization

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

serialization/serialization
===========================

Library defining a Serializer and a Deserializer interface and basic utilities

4.1.0(1y ago)7867.0k↑154.3%2[1 PRs](https://github.com/wmde/Serialization/pulls)14GPL-2.0-or-laterPHPPHP &gt;=7.4CI failing

Since Jul 13Pushed 1y ago23 watchersCompare

[ Source](https://github.com/wmde/Serialization)[ Packagist](https://packagist.org/packages/serialization/serialization)[ Docs](https://github.com/wmde/Serialization)[ RSS](/packages/serialization-serialization/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (9)Dependencies (2)Versions (15)Used By (14)

Serialization
=============

[](#serialization)

[![Build Status](https://github.com/wmde/Serialization/actions/workflows/lint-and-test.yaml/badge.svg?branch=master)](https://github.com/wmde/Serialization/actions/workflows/lint-and-test.yaml)[![Code Coverage](https://camo.githubusercontent.com/83a16f33cfab306e3a8a709c98c6b78e147d69d34195b743b0c84cf3d5a0425d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f53657269616c697a6174696f6e2f6261646765732f636f7665726167652e706e673f733d63316462303466383866373633663633646330663064383331356366396238343931666338316536)](https://scrutinizer-ci.com/g/wmde/Serialization/)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/b9c185fe2c66748b0f81629bd51763ab392d7498db298d39fedba76bd9e02a8e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f53657269616c697a6174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f733d64323562396437636263346137333738313765626630373264326534623535623062643862363632)](https://scrutinizer-ci.com/g/wmde/Serialization/)

On Packagist: [![Latest Stable Version](https://camo.githubusercontent.com/44158cc5b43f3732c4df2d7f1ae5cad6c37eab9628b1dd29535475663f13d79f/68747470733a2f2f706f7365722e707567782e6f72672f73657269616c697a6174696f6e2f73657269616c697a6174696f6e2f76657273696f6e2e706e67)](https://packagist.org/packages/serialization/serialization)[![Download count](https://camo.githubusercontent.com/11b5916e28cf21294e371a815d77a6e16642a9d7e410914fac45f76500f1f1fe/68747470733a2f2f706f7365722e707567782e6f72672f73657269616c697a6174696f6e2f73657269616c697a6174696f6e2f642f746f74616c2e706e67)](https://packagist.org/packages/serialization/serialization)

Small library defining a Serializer and a Deserializer interface.

Also contains various Exceptions and a few basic (de)serialization utilities.

Requirements
------------

[](#requirements)

- PHP 7.4 or later

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

[](#installation)

You can use [Composer](http://getcomposer.org/) to download and install this package as well as its dependencies. Alternatively you can simply clone the git repository and take care of loading yourself.

### Composer

[](#composer)

To add this package as a local, per-project dependency to your project, simply add a dependency on `serialization/serialization` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Serialization 4.x:

```
{
    "require": {
        "serialization/serialization": "^4.0"
    }
}

```

### Manual

[](#manual)

Get the Serialization code, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. This file also specifies how the resources provided by this library should be loaded, in its "autoload" section.

Usage
-----

[](#usage)

### Library structure

[](#library-structure)

This component contains two sub parts, one containing serialization related code, the other holding deserialization specific code. The former is located in the Serializers namespace, while the latter resides in the Deserializers one. Both namespaces are PSR-0 mapped onto the src directory.

### Interfaces

[](#interfaces)

The primary thing provided by this library are the Serializer and Deserializer namespaces. A set of Exceptions each process typically can encounter are also provided, and are located in respective Exceptions namespaces. They all derive from `SerializationException`/`DeserializationException`.

The main interfaces define the `serialize`/`deserialize` methods that do the actual work. In addition there are interfaces with a `isSerializerFor`/`isDeserializerFor` method respectively that allows finding out if a given (de)serializer can process a given input.

### Utilities

[](#utilities)

A DispatchingSerializer and a DispatchingDeserializer are two generally usable implementations of the interfaces that are included in this library. They both do the same thing: contain a list of (de)serializers and dispatch calls to the (de)serialize method to the appropriate one. This allows for bundling multiple (de)serializers together and enables handling of nested data with variable structure.

Tests
-----

[](#tests)

This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these tests using the PHPUnit configuration file found in the root directory. The tests can also be run via TravisCI, as a TravisCI configuration file is also provided in the root directory.

The library contains some code that was split factored out of concrete classes part of [AskSerialization](https://github.com/wmde/AskSerialization). Those tests have not been split, hence the low apparent coverage. It is recommended to run the AskSerialization tests when making changes to the code in question.

Authors
-------

[](#authors)

Serialization has been written by [Jeroen De Dauw](https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw)as [Wikimedia Germany](https://wikimedia.de) employee for the [Wikidata project](https://wikidata.org/).

Release notes
-------------

[](#release-notes)

### 5.0.0 (dev)

[](#500-dev)

### 4.1.0 (2024-12-11)

[](#410-2024-12-11)

- Drop support for PHP 7.2, 7.3
- Upgrade codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0)
- Make nullable type parameter declarations explicit for compatibility with PHP 8.4
- Type hinted the `$previous` parameter as `Throwable` instead of `Exception`
- Updated minimum required PHP version from `5.5.9` to `7.2` (HHVM is no longer supported)
- Updated to `GPL-2.0-or-later` according to SPDX v3
- Added a default message to the MissingTypeException

### 4.0.0 (2017-10-25)

[](#400-2017-10-25)

- Removed the `Serialization_VERSION` constant.
- Removed underspecified `StrategicDeserializer` along with the abstract `TypedDeserializationStrategy` base class.
- Removed undocumented `TypedObjectDeserializer::requireAttributes`.
- Declared various protected properties and methods private:
    - `DispatchingDeserializer::$deserializers`
    - `DispatchingDeserializer::assertAreDeserializers`
    - `DispatchingSerializer::$serializers`
    - `DispatchingSerializer::assertAreSerializers`
    - `InvalidAttributeException::$attributeName`
    - `InvalidAttributeException::$attributeValue`
    - `MissingAttributeException::$attributeName`
    - `TypedObjectDeserializer::$objectType`
    - `UnsupportedObjectException::$unsupportedObject`
    - `UnsupportedTypeException::$unsupportedType`
- Deprecated pure utility functions on `TypedObjectDeserializer`:
    - `assertAttributeInternalType`
    - `assertAttributeIsArray`
    - `requireAttribute`
- Added default messages to `InvalidAttributeException`, `MissingAttributeException`, and `UnsupportedTypeException`.
- Added documentation to the `Serializer` and `Deserializer` interfaces.
- Updated minimal required PHP version from 5.3 to 5.5.9.

### 3.2.1 (2014-08-19)

[](#321-2014-08-19)

- Tested against hhvm-nightly
- Tests now run in strict mode

### 3.2.0 (2014-05-20)

[](#320-2014-05-20)

- Made SerializationException non-abstract

### 3.1.0 (2014-03-18)

[](#310-2014-03-18)

- TypedObjectDeserializer now explicitly implements DispatchableDeserializer.

### 3.0.0 (2014-03-05)

[](#300-2014-03-05)

- Split is(Des/S)erializerFor methods off into new Dispatchable(Des/S)erializer interfaces
- Changed from classmap based autoloading to PSR-4 based autoloading
- Improved PHPUnit bootstrap

### 2.2.0 (2013-12-11)

[](#220-2013-12-11)

- Removed custom autoloader in favour of using the declarative system provided by Composer

### 2.1.0 (2013-11-19)

[](#210-2013-11-19)

- The type key in TypedObjectDeserializer can now be specified via a constructor argument
- TypedObjectDeserializer now has some tests in this component itself
- The documentation was somewhat improved

### 2.0.0 (2013-09-05)

[](#200-2013-09-05)

- Renamed Serializer::canSerialize to Serializer::isDeserializerFor
- Renamed Deserializer::canDeserialize to Deserializer::isDeserializerFor

### 1.0.0 (2013-07-13)

[](#100-2013-07-13)

- Initial release.

Links
-----

[](#links)

- [Serialization on Packagist](https://packagist.org/packages/serialization/serialization)
- [Serialization on Ohloh](https://www.ohloh.net/p/serialization-php)
- [TravisCI build status](https://travis-ci.org/wmde/Serialization)
- [Serialization on ScrutinizerCI](https://scrutinizer-ci.com/g/wmde/Serialization/)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community37

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~417 days

Recently: every ~964 days

Total

11

Last Release

569d ago

Major Versions

1.0 → 2.02013-09-09

2.2 → 3.02014-03-05

3.2.1 → 4.0.02017-10-25

3.2.2 → 4.1.02024-12-11

PHP version history (3 changes)1.0PHP &gt;=5.3.0

4.0.0PHP &gt;=5.5.9

4.1.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/054adb441e7ee248ec924bc45fa793835c284710eb31627587fa5de21bab9e96?d=identicon)[wmde](/maintainers/wmde)

![](https://www.gravatar.com/avatar/5406ed1d40d50ffc61d67e9f5149914dbfe0b8a52bdf297299f5ccfab0a73d91?d=identicon)[thiemowmde](/maintainers/thiemowmde)

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

![](https://www.gravatar.com/avatar/8cc7ef1a982b9520bbe19e7699556cda12f528e2fcece72d0d18e79b6457794c?d=identicon)[mariushoch](/maintainers/mariushoch)

![](https://avatars.githubusercontent.com/u/135401?v=4)[Katie Filbert](/maintainers/filbertkm)[@filbertkm](https://github.com/filbertkm)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (54 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (17 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (10 commits)")[![lucaswerkmeister](https://avatars.githubusercontent.com/u/2346599?v=4)](https://github.com/lucaswerkmeister "lucaswerkmeister (10 commits)")[![manicki](https://avatars.githubusercontent.com/u/3524114?v=4)](https://github.com/manicki "manicki (7 commits)")[![codders](https://avatars.githubusercontent.com/u/17782?v=4)](https://github.com/codders "codders (5 commits)")[![itamargiv](https://avatars.githubusercontent.com/u/6132917?v=4)](https://github.com/itamargiv "itamargiv (5 commits)")[![mariushoch](https://avatars.githubusercontent.com/u/2446964?v=4)](https://github.com/mariushoch "mariushoch (4 commits)")[![outdooracorn](https://avatars.githubusercontent.com/u/43674967?v=4)](https://github.com/outdooracorn "outdooracorn (4 commits)")[![micgro42](https://avatars.githubusercontent.com/u/7372507?v=4)](https://github.com/micgro42 "micgro42 (3 commits)")[![rosalieper](https://avatars.githubusercontent.com/u/15235452?v=4)](https://github.com/rosalieper "rosalieper (2 commits)")[![wiese](https://avatars.githubusercontent.com/u/167557?v=4)](https://github.com/wiese "wiese (1 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (1 commits)")[![Ladsgroup](https://avatars.githubusercontent.com/u/5351225?v=4)](https://github.com/Ladsgroup "Ladsgroup (1 commits)")[![Tpt](https://avatars.githubusercontent.com/u/458123?v=4)](https://github.com/Tpt "Tpt (1 commits)")

---

Tags

serializerserializationdeserializationwikidataunserializationdeserializer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/serialization-serialization/health.svg)

```
[![Health](https://phpackages.com/badges/serialization-serialization/health.svg)](https://phpackages.com/packages/serialization-serialization)
```

###  Alternatives

[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k141.9M929](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k92.4M679](/packages/jms-serializer-bundle)[flix-tech/avro-serde-php

A library to serialize and deserialize Avro records making use of the confluent schema registry

684.2M21](/packages/flix-tech-avro-serde-php)[wikibase/data-model-serialization

Serializers and deserializers for the Wikibase DataModel

10197.4k8](/packages/wikibase-data-model-serialization)

PHPackages © 2026

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