PHPackages                             opensoft/simple-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. opensoft/simple-serializer

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

opensoft/simple-serializer
==========================

Simple Serializer

1.1.1(10y ago)1914.2k8[1 issues](https://github.com/opensoft/simple-serializer/issues)[1 PRs](https://github.com/opensoft/simple-serializer/pulls)1MITPHPPHP &gt;=5.3.3

Since Dec 15Pushed 5y ago5 watchersCompare

[ Source](https://github.com/opensoft/simple-serializer)[ Packagist](https://packagist.org/packages/opensoft/simple-serializer)[ Docs](http://github.com/opensoft/simple-serializer)[ RSS](/packages/opensoft-simple-serializer/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (11)Used By (1)

Simple-Serializer
=================

[](#simple-serializer)

[![Build Status](https://camo.githubusercontent.com/7839df10992ed077f7042221646e49341edc58154eb37b2cf4b741d7b528864b/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f70656e736f66742f73696d706c652d73657269616c697a65722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/opensoft/simple-serializer)[![Total Downloads](https://camo.githubusercontent.com/130c69fdbddc21565284c2fd8f3375841c32e8db1008cb68807326f3372a900a/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e736f66742f73696d706c652d73657269616c697a65722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/opensoft/simple-serializer)[![Latest Stable Version](https://camo.githubusercontent.com/6c15f06f1b30ecc4c05c8901b0f0984e8b5e543b5ef84575cbe8a5d2dcacf960/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e736f66742f73696d706c652d73657269616c697a65722f762f737461626c652e706e67)](https://packagist.org/packages/opensoft/simple-serializer)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/527b157712e10d0bc866001ab88d24af5eac710380efb3616b932b66e29066c2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f70656e736f66742f73696d706c652d73657269616c697a65722f6261646765732f7175616c6974792d73636f72652e706e673f733d63653762623862653735353235643531396434363631313438353636383162306462643935383438)](https://scrutinizer-ci.com/g/opensoft/simple-serializer/)[![SensioLabsInsight](https://camo.githubusercontent.com/7cca78fd7cff3e7aa31b64286c76df93bbba89af780071601fb927fab7d75e47/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39353031393366322d613361372d343131372d613236372d6534623163393566653562332f6d696e692e706e67)](https://insight.sensiolabs.com/projects/950193f2-a3a7-4117-a267-e4b1c95fe5b3)

Introduction
------------

[](#introduction)

Simple-Serializer allows you to serialize your objects into a requested output format such as JSON. The library is written to work with DTO objects in the REST services.

Built-in features include:

- (de-)serialize object graphs
- supports boolean, integer, double, DateTime&lt;format&gt;, array, T, array&lt;T&gt;, null types, where "T" - is some PHP object.
- configurable via YAML
- three unserialize mode (non-strict, medium strict, strict)

Unserialize mode: Non-Strict mode - serializer does not check incoming parameters Medium Strict - serializer extra check incoming parameters and if they exist throw InvalidArgumentException Strict - serializer extra check incoming parameters completely as expected if there are extra arguments or missing some, it throws an exception.

Some Restrictions:

- object must have configuration for serialize/unserialize

Possible TODO list:

- (de-)serialize object graphs of any complexity including circular references
- configurable via PHP, XML, or annotations
- custom integrates with Doctrine ORM, et. al.

It should be noted that Simple-Serializer is realy simple library with minimum configuration, but it provides wide opportunity for create REST API.

[![Build Status](https://camo.githubusercontent.com/7839df10992ed077f7042221646e49341edc58154eb37b2cf4b741d7b528864b/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6f70656e736f66742f73696d706c652d73657269616c697a65722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/opensoft/simple-serializer)

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

[](#installation)

To install Simple-Serializer with Composer just add the following to your `composer.json` file:

```
    // composer.json
    {
        // ...
        require: {
            // ...
            "opensoft/simple-serializer": "dev-master"
        }
    }
```

Then, you can install the new dependencies by running Composer's `update`command from the directory where your `composer.json` file is located:

```
$ php composer.phar update

```

Configuration
-------------

[](#configuration)

```
MyBundle\Resources\config\serializer\ClassName.yml
    Fully\Qualified\ClassName:
        properties:
            some-property:
                expose: true
                type: string
                serialized_name: foo
                since_version: 1.0
                until_version: 2.0
                groups: ['get','patch']
```

- expose
- true
- false (default)
- type
- integer
- boolean
- double
- string
- array
- T - fully qualified class name
- array&lt;T&gt;
- DateTime
- DateTime&lt;format&gt;
- format could be name of DateTime constant (COOKIE, ISO8601), string or empty (default format is ISO8601)
- serialized\_name
- default value is equal name property
- since\_version
- string
- until\_version
- string
- groups
- array
- null\_skipped
- true
- false (default)

Serializing Objects
-------------------

[](#serializing-objects)

Most common usage is probably to serialize objects. This can be achieved very easily:

```
