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

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

andreiavrammsd/serializer
=========================

JSON string to object. Object/array to JSON.

v1.0.0(6y ago)310.2k↓34.6%2MITPHPPHP &gt;=7.1

Since Sep 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/andreiavrammsd/serializer)[ Packagist](https://packagist.org/packages/andreiavrammsd/serializer)[ RSS](/packages/andreiavrammsd-serializer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (9)Used By (2)

PHP Serializer
==============

[](#php-serializer)

[![build](https://github.com/andreiavrammsd/serializer/workflows/test/badge.svg)](https://github.com/andreiavrammsd/serializer/actions)

### Very basic serializer/unserializer/toarray. Also transforms data by types and/or callbacks.

[](#very-basic-serializerunserializertoarray-also-transforms-data-by-types-andor-callbacks)

Currently handles only JSON.

Install
-------

[](#install)

```
composer require andreiavrammsd/serializer
```

Usage
-----

[](#usage)

```
$input = '{...}';
$class = ObjectClass::class;

$serializer = Serializer\SerializerBuilder::instance()->build();
// OR
$serializer = Serializer\Factory::create();

$object = $serializer->unserialize($input, $class);

$serializer->serialize($object);

$serializer->toArray($object);
```

See [examples](./examples) and [tests](./tests).

Property annotations (all annotations are optional)
---------------------------------------------------

[](#property-annotations-all-annotations-are-optional)

- Property: name of key in input. If not set, the variable name is used.
- Type: If set, the value will be transformed as follows
    - int, float, string, bool, array: will cast value to the [type](https://secure.php.net/manual/en/language.types.intro.php#language.types.intro).
    - collection: value will be wrapped by a [countable iterator with array access](./src/Collection.php).
    - [DateTime](https://secure.php.net/manual/en/book.datetime.php): creates a DateTime object, formatting the value by [formats](https://secure.php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters) given as arguments; first valid format is used.
    - Fully qualified class name: the value will be parsed into the given class.
    - Array of class: the value will be parsed into an array with each element parsed into the given class.
    - Collection of class: the value will be parsed into a [collection](./src/Collection.php) with each element parsed into the given class.
- Callback: A callable (function or class method) is accepted (with optional parameters). The value will be passed to the callable (with the optional parameters, if set), and the new value will be the result of the callable.

#### Examples

[](#examples)

```
@Serializer\Property("first_name")

@Serializer\Type("int")
@Serializer\Type("float")
@Serializer\Type("string")
@Serializer\Type("bool")
@Serializer\Type("array")
@Serializer\Type("collection")
@Serializer\Type("DateTime","Y-m-d H:i", "Y-m-d")
@Serializer\Type("Entity\User")
@Serializer\Type("array[Entity\User]")
@Serializer\Type("collection[Entity\User]")

@Serializer\Callback("strtoupper")
@Serializer\Callback("substr", "0", "3")
@Serializer\Callback("[User\NameFormatter, firstName]")
@Serializer\Callback("[User\NameFormatter, lastName]", "1", "3")

@Serializer\IgnoreNull() // Ignores null values when serializing or converting to array.

```

Object class annotations
------------------------

[](#object-class-annotations)

- Collection: a class annotated with Collection and extending the [Collection](./src/Collection.php) class will be a collection class with its items of the specified class type.

#### Examples

[](#examples-1)

```
@Serializer\Collection("Entity\User")

```

Development
-----------

[](#development)

- Requirements: Docker, Make
- Build and install dev container:
    - `make build PHPVERSION=7.4`
    - `make install PHPVERSION=7.4`
- Run QA tools: `make PHPVERSION=7.4`
- Work inside dev container: `make run PHPVERSION=7.4` then `make localqa`
- Remove Docker image: `make clean PHPVERSION=7.4`

Developed with [PhpStorm](https://www.jetbrains.com/?from=serializer)

[![JetBrains](jetbrains.svg)](https://www.jetbrains.com/?from=serializer)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~64 days

Recently: every ~108 days

Total

8

Last Release

2334d ago

Major Versions

v0.6.0 → v1.0.02019-12-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/6395aad28cc0faf830072eaf235cee709a219d30070484e0ab143c82a1959592?d=identicon)[andreiavrammsd](/maintainers/andreiavrammsd)

---

Top Contributors

[![andreiavrammsd](https://avatars.githubusercontent.com/u/6795248?v=4)](https://github.com/andreiavrammsd "andreiavrammsd (105 commits)")

---

Tags

jsonphpserializetransformerunserializejsonserializertransformerunserializer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[zumba/json-serializer

Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.

129743.7k13](/packages/zumba-json-serializer)[laktak/hjson

JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments.

86233.7k12](/packages/laktak-hjson)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)[type-lang/mapper

Library for mapping variable types to other types

347.1k](/packages/type-lang-mapper)[opensoft/simple-serializer

Simple Serializer

1914.2k1](/packages/opensoft-simple-serializer)

PHPackages © 2026

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