PHPackages                             vuryss/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. vuryss/serializer

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

vuryss/serializer
=================

A fast, extensible PHP data structures serializer &amp; deserializer

v4.0.0(3mo ago)111.8k↓29%[2 issues](https://github.com/vuryss/serializer/issues)[5 PRs](https://github.com/vuryss/serializer/pulls)2MITPHPPHP ^8.5CI passing

Since Jun 24Pushed 3w ago2 watchersCompare

[ Source](https://github.com/vuryss/serializer)[ Packagist](https://packagist.org/packages/vuryss/serializer)[ RSS](/packages/vuryss-serializer/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (26)Versions (30)Used By (2)

Fast serialization library
==========================

[](#fast-serialization-library)

[![Tests](https://github.com/vuryss/serializer/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/vuryss/serializer/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/aaf111bfff61312377c64ecabb55343f8d1c5412899a04d85ed889669b6bc126/68747470733a2f2f636f6465636f762e696f2f67682f7675727973732f73657269616c697a65722f67726170682f62616467652e7376673f746f6b656e3d6b4b305a486833726141)](https://codecov.io/gh/vuryss/serializer)[![Codacy Badge](https://camo.githubusercontent.com/99353705d03cd20a2285a963cc980c129c9ccb4ff0efa74ff4b16c606221925e/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3736306533643466393835323438666438626234376239343738373362383437)](https://app.codacy.com/gh/vuryss/serializer/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![CodeFactor](https://camo.githubusercontent.com/43b99ce62f9f557dcf3a66f4f2f6a161bf455166ffadd7bc55beac28e7c5f974/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f7675727973732f73657269616c697a65722f6261646765)](https://www.codefactor.io/repository/github/vuryss/serializer)[![GitHub Release](https://camo.githubusercontent.com/c063addb7c28c9cc3da7ed4de909eb878ca9aa87af5241568d2d3489b4a9f2b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7675727973732f73657269616c697a6572)](https://camo.githubusercontent.com/c063addb7c28c9cc3da7ed4de909eb878ca9aa87af5241568d2d3489b4a9f2b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7675727973732f73657269616c697a6572)[![GitHub License](https://camo.githubusercontent.com/a280cf0a331618d0758e722e3b05fb4ac92ed39c0615f479280226c0f401da4f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7675727973732f73657269616c697a6572)](https://camo.githubusercontent.com/a280cf0a331618d0758e722e3b05fb4ac92ed39c0615f479280226c0f401da4f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7675727973732f73657269616c697a6572)

Serializes and deserializes complex data structures to and from json. Ideas taken from Symfony's Serializer component, Serde and others.

Symfony serializer was very flexible, but also very slow. This library tries to be as fast as possible.

Supports modern PHP projects with fully typed properties. Older codebases with no types would not work.

Benchmarks comparing this library with Symfony Serializer and Serde can be found here: [Here](https://github.com/vuryss/serializer-benchmark)

- [Fast serialization library](#fast-serialization-library)
    - [Installation](#installation)
    - [Features](#features)
        - [Serialization](#serialization)
        - [Deserialization](#deserialization)
        - [Caching - optional, but highly recommended, otherwise the library will be slow](#caching---optional--but-highly-recommended--otherwise-the-library-will-be-slow)
        - [Custom object property serialized name](#custom-object-property-serialized-name)
        - [Serialization groups](#serialization-groups)
        - [Deserialization groups](#deserialization-groups)
        - [Custom date format](#custom-date-format)
        - [Enforce date format](#enforce-date-format)
        - [Convert date to timezone](#convert-date-to-timezone)
        - [Ignore property](#ignore-property)
        - [Handling of NULL values](#handling-of-null-values)
        - [Support for json serializable objects](#support-for-json-serializable-objects)
        - [Support for Symfony Serializer attributes](#support-for-symfony-serializer-attributes)
    - [Build, run &amp; test locally](#build--run---test-locally)

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

[](#installation)

```
composer require vuryss/serializer
```

The library supports Symfony 7.4 LTS and Symfony 8.x.

Features
--------

[](#features)

### Serialization

[](#serialization)

- Properties are serialized if they are either public or have a getter method.

```
$person = new Person();
$person->firstName = 'Maria';
$person->lastName = 'Valentina';
$person->age = 36;
$person->isStudent = false;

$serializer = new Serializer();
$json = $serializer->serialize($person);
// {"firstName":"Maria","lastName":"Valentina","age":36,"isStudent":false}
```

### Deserialization

[](#deserialization)

- Properties are deserialized if they are public, instantiable in public constructor or have a setter method.

```
$json = '{"firstName":"Maria","lastName":"Valentina","age":36,"isStudent":false}';
$serializer = new Serializer();
$person = $serializer->deserialize($json, Person::class);
```

### Caching - optional, but highly recommended, otherwise the library will be slow

[](#caching---optional-but-highly-recommended-otherwise-the-library-will-be-slow)

Supports PSR-6 CacheItemPoolInterface:

No need to chain in-memory cache with external cache, the library will do it for you. Cache will be called once per used class (used in serialization or deserialization), then will be cached in memory until the script ends.

```
$pst6cache = new CacheItemPool(); // Some PSR-6 cache implementation
$serializer = new Serializer(
    metadataExtractor: new CachedMetadataExtractor(
        new MetadataExtractor(),
        $pst6cache,
    ),
);
```

### Custom object property serialized name

[](#custom-object-property-serialized-name)

```
class SomeClass
{
    #[SerializerContext(name: 'changedPropertyName')]
    public string $someProperty;
}
```

### Serialization groups

[](#serialization-groups)

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(groups: ['group1'])]
    public string $property1;

    // Has implicit group 'default'
    public string $property2;
}

$serializer = new Serializer();
$object = new SomeClass();
$object->property1 = 'value1';
$object->property2 = 'value2';
$serializer->serialize($object, context: [Context::GROUPS => ['group1']]); // {"property1":"value1"}
```

### Deserialization groups

[](#deserialization-groups)

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(groups: ['group1'])]
    public string $property1;

    // Has implicit group 'default'
    public string $property2;
}

$serializer = new Serializer();
$data = '{"property1":"value1","property2":"value2"}';
$object = $serializer->deserialize($data, SomeClass::class, context: [Context::GROUPS => ['group1']]);
isset($object->property1); // true
isset($object->property2); // false
```

### Custom date format

[](#custom-date-format)

On serialization the format will always be respected. On deserialization the format will be used to parse the date. However on deserialization by default if the date is not in the provided format, it will be parsed as is, given that DateTime constructor can parse it.

Per property:

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(context: [Context::DATETIME_FORMAT => 'Y-m-d'])]
    public DateTime $someDate;
}
```

Or globally:

```
use Vuryss\Serializer\Context;

$serializer = new Serializer(
    context: [
        Context::DATETIME_FORMAT => \DateTimeInterface::RFC2822,
    ]
);
```

### Enforce date format

[](#enforce-date-format)

If strict data time format is required during deserialization then, you can use the `Context::DATETIME_FORMAT_STRICT` context option:

Per property:

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(context: [
        Context::DATETIME_FORMAT => 'Y-m-d',
        Context::DATETIME_FORMAT_STRICT => true
    ])]
    public DateTime $someDate;
}
```

Or globally:

```
use Vuryss\Serializer\Context;

$serializer = new Serializer(
    context: [
        Context::DATETIME_FORMAT => 'Y-m-d',
        Context::DATETIME_FORMAT_STRICT => true
    ]
);
```

### Convert date to timezone

[](#convert-date-to-timezone)

After denormalization, the `DateTime` object can be converted to a specific timezone.

Per property:

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(context: [Context::DATETIME_TARGET_TIMEZONE => 'UTC'])]
    public DateTime $someDate;
}
```

Or globally:

```
use Vuryss\Serializer\Context;

$serializer = new Serializer(
    context: [
        Context::DATETIME_TARGET_TIMEZONE => 'UTC',
    ]
);
```

### Ignore property

[](#ignore-property)

Those properties will not be included in the serialized values during serialization and will not be populated with provided values during deserialization.

```
class SomeClass
{
    #[SerializerContext(ignore: true)]
    public string $someProperty;
}
```

### Handling of NULL values

[](#handling-of-null-values)

- By default, NULL values are included in the serialized value.

To disable this you can use the `Context::SKIP_NULL_VALUES` context option:

Per property:

```
use Vuryss\Serializer\Context;

class SomeClass
{
    #[SerializerContext(context: [Context::SKIP_NULL_VALUES => true])]
    public ?string $someProperty;
}
```

Or globally:

```
use Vuryss\Serializer\Context;

$serializer = new Serializer(
    context: [
        Context::SKIP_NULL_VALUES => true,
    ]
);
```

### Support for json serializable objects

[](#support-for-json-serializable-objects)

If an object implements the `JsonSerializable` interface, the `jsonSerialize` method will be called and the result will be serialized.

### Support for Symfony Serializer attributes

[](#support-for-symfony-serializer-attributes)

This library aims to be a drop-in replacement for Symfony Serializer. It supports the following attributes:

- Groups
- SerializedName
- Ignore
- DiscriminatorMap

Build, run &amp; test locally
-----------------------------

[](#build-run--test-locally)

To enter the prepared container environment:

```
docker-compose up -d
docker-compose exec library bash
```

Install package dependencies:

```
docker-compose exec library composer install -o
```

Run the default local quality suite against the locked latest dependencies (Symfony 8.x):

```
docker-compose exec library composer qa
```

Reproduce the Symfony compatibility matrix locally when needed:

```
docker-compose exec library composer deps:lowest
docker-compose exec library composer qa
docker-compose exec library composer deps:highest
docker-compose exec library composer qa
```

`composer deps:lowest` rewrites composer.lock to the minimum supported dependency set, while `composer deps:highest` restores the latest supported set.

HTML Coverage locally:

```
docker-compose exec library XDEBUG_MODE=coverage vendor/bin/pest --coverage --coverage-html=coverage
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance68

Regular maintenance activity

Popularity27

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% 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 ~34 days

Recently: every ~86 days

Total

19

Last Release

113d ago

Major Versions

v1.11.0 → v2.0.02025-06-19

v2.0.0 → v3.0.02025-12-15

v3.0.0 → v4.0.02026-03-12

PHP version history (3 changes)v1.0.0PHP ^8.3

v1.10.0PHP ^8.4

v4.0.0PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/70759f4deef30c94bac54f3c2243202d62595f3b55c9a4f88b19f32c1bcfad0f?d=identicon)[vuryss](/maintainers/vuryss)

---

Top Contributors

[![vuryss](https://avatars.githubusercontent.com/u/7021705?v=4)](https://github.com/vuryss "vuryss (96 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (38 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")[![frwuttke](https://avatars.githubusercontent.com/u/108340101?v=4)](https://github.com/frwuttke "frwuttke (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.4k67.4M263](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[api-platform/metadata

API Resource-oriented metadata attributes and factories

275.0M219](/packages/api-platform-metadata)[symfony/serializer-pack

A pack for the Symfony serializer

1.1k29.3M258](/packages/symfony-serializer-pack)

PHPackages © 2026

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