Library defining a Serializer and a Deserializer interface and basic utilities

Installs: 80 339

Dependents: 14

Stars: 3

Watchers: 18

Forks: 2

3.2.1 2014-08-19 01:53 UTC


Build Status Code Coverage Scrutinizer Quality Score

On Packagist: Latest Stable Version Download count

Small library defining a Serializer and a Deserializer interface.

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


  • PHP 5.3 or later


You can use Composer 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.


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 3.x:

    "require": {
        "serialization/serialization": "~3.0"


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.


Library structure

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


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 (Des/S)erializationException.

Both interfaces define two methods: a (de)serialize method that does the actual work, and a can(Des/S)erialize method that allows finding out if a given (de)serializer can process a given input.


A DispatchingSerializer and a DispatcingDeserializer 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.


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. 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.


Serialization has been written by Jeroen De Dauw as Wikimedia Germany employee for the Wikidata project.

Release notes

3.2.1 (2014-08-19)

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

3.2 (2014-05-20)

  • Made SerializationException non-abstract

3.1 (2014-03-18)

  • TypedObjectDeserializer now explicitly implements DispatchableDeserializer.

3.0 (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 (2013-12-11)

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

2.1 (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 (2013-09-05)

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

1.0 (2013-07-13)

  • Initial release.