PHPackages                             dimaskao/library\_for\_serializing\_objects - 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. dimaskao/library\_for\_serializing\_objects

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

dimaskao/library\_for\_serializing\_objects
===========================================

This library can serialize your php objects into JSON, YAML and XML.

v3.0.1(5y ago)05PHPPHP &gt;=7.4

Since Aug 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Dimaskao/Library_for_serializing_objects)[ Packagist](https://packagist.org/packages/dimaskao/library_for_serializing_objects)[ RSS](/packages/dimaskao-library-for-serializing-objects/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Library for serializing
=======================

[](#library-for-serializing)

This library can serialize your php objects into `JSON`, `YAML` and `XML`.

Table of contents
=================

[](#table-of-contents)

- [Installation](#Installation)
- [How to use](#How-to-use)
    - [General](#General)
    - [Field selection](#Field-selection)
- [Library extension](#Library-extension)
- [Example](#Example)

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

[](#installation)

You can use composer to install this extension.

Just run:

```
$ composer require dimaskao/library_for_serializing_objects

```

How to use
----------

[](#how-to-use)

### General

[](#general)

At first include this library classes:

```
require_once __DIR__ . '/XXXXX/vendor/autoload.php';

use Dimaskao\Serializer\JSON   //|\
use Dimaskao\Serializer\XML    //|- Choose what you need
use Dimaskao\Serializer\YAML   //|/
```

Where `XXXXX` path to library root folder.

If you want to serialize an object, you should create a new `JSON`, `_YAML_` or `XML` object.

```
$json = new JSON();
$yaml = new YAML();
$xml = new XML();
```

Then use `->serialize()` method and pass an object to it. This method will return string with serialized object.

```
$json = new JSON();
$json->serialize($obj);
```

### Field selection

[](#field-selection)

If you do not want to serialize the all object, you can select individual fields. For this pass array in `serialize()` with name of field.

```
$json = new JSON();
$json->serialize($obj, ["value1", "value3"]);
```

Library extension
-----------------

[](#library-extension)

If you would add new formats, you should create your own class which extends `AbstractSerializer.php` and implements `SerializerInterface.php`.

```
require_once __DIR__ . '/vendor/autoload.php';
use Dimaskao\Serializer\AbstractSerializer;
use Dimaskao\Serializer\SerializerInterface;

class YourFormat extends AbstractSerializer implements SerializerInterface {

}
```

This class must have a `serialize()` method. Use `$this->get_data()` to get all fields in an object.

`$elemetn_list` - optional array with the fields to get. Watch [Field selection](#Field-selection).

```
class YourFormat extends AbstractSerializer implements SerializerInterface {
    public function serialize($obj, $elemetn_list = []){
        $public_value = $this->get_data($obj, $elemetn_list);
    }
}
```

Then you can do whatever you want with `$public_value`, for example:

```
return json_encode($public_value)
```

Example
-------

[](#example)

Let's see how it works using the YAML example.

```
//Include library
require_once __DIR__ . '/vendor/autoload.php';

use Dimaskao\Serializer\YAML;

//Creating test class
class Test {

    public $value = "Value";
    public $value1 = "Value1";
    private $value2 = ["Value2.1" => "first", "Value2.2" => 2];
    protected $value3;

    function __construct($item) {
        $this->value3 = $item;
    }
}
//Creating test object
$test = new Test("Value3");

//Creating YAML object
$yaml = new YAML();

//Saving serialized object
$serialized_obj = $yaml->serialize($test, ["value", "value2"]);

//Views results
echo "";
print_r($serialized_obj);
echo "";
```

As a result, we get.

```
---
value: Value
value2:
  Value2.1: first
  Value2.2: 2
...
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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 ~0 days

Total

5

Last Release

2149d ago

Major Versions

v1.0.1 → 2.0.02020-08-12

2.0.0 → v3.0.02020-08-13

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59502015?v=4)[Dmytro](/maintainers/Dimaskao)[@Dimaskao](https://github.com/Dimaskao)

---

Top Contributors

[![Dimaskao](https://avatars.githubusercontent.com/u/59502015?v=4)](https://github.com/Dimaskao "Dimaskao (27 commits)")

### Embed Badge

![Health badge](/badges/dimaskao-library-for-serializing-objects/health.svg)

```
[![Health](https://phpackages.com/badges/dimaskao-library-for-serializing-objects/health.svg)](https://phpackages.com/packages/dimaskao-library-for-serializing-objects)
```

###  Alternatives

[craftcms/cms

Craft CMS

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

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[aeliot/todo-registrar

Register TODOs from source code in issue tracker

153.0k](/packages/aeliot-todo-registrar)

PHPackages © 2026

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