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

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

kudrmichal/serializer
=====================

Simple XML/JSON object mapper for PHP 8.0+

2.6.4(3y ago)212.9k1[5 issues](https://github.com/KudrMichal/Serializer/issues)[1 PRs](https://github.com/KudrMichal/Serializer/pulls)proprietaryPHPCI failing

Since Feb 25Pushed 3y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (17)Used By (0)

Simple XML/JSON object mapper
=============================

[](#simple-xmljson-object-mapper)

kudrmichal/serializer is a PHP object xml/json mapper for PHP 8.0+

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

[](#requirements)

kudrmichal/serializer requires PHP 8.0 or higher.

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

[](#installation)

To install the latest version of `kudrmichal/serializer` use [Composer](https://getcomposer.org).

```
$ composer require kudrmichal/serializer

```

JSON Usage
----------

[](#json-usage)

Let's create two test classes

```
use KudrMichal\Serializer\Json\Metadata as JSON;

class Test
{
    public function __construct(
        #[JSON\Property(name:"testInt")]
        private int $testInteger,
        #[JSON\Property]
        private string $testString,
        #[JSON\Property]
        private bool $testBoolean,
        #[JSON\PropertyArray]
        private array $testArray,
        #[JSON\Property]
        private TestObject $testObject,
        #[JSON\PropertyArray(type:TestObject::class)]
        private array $testObjectsArray,
    ) {}

    //getters, setters, etc.
}

class TestObject
{
    public function __construct(
        #[JSON\Property] private int $testObjectInt,
        #[JSON\Property] private string $testObjectString,
        #[JSON\Property] private bool $testObjectBoolean,
        #[JSON\PropertyArray] private array $testObjectArray
    ) {}

    //getters, setters, etc.
}

```

JSON string serializing to PHP object

```

$json =
