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 today

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 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

2096d ago

Major Versions

v1.0.1 → 2.0.02020-08-12

2.0.0 → v3.0.02020-08-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/30b8f039bba7550ba7ef642afeeb6b9c73757527a03074209051410b13254501?d=identicon)[Dimaskao](/maintainers/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

[daux/daux.io

Documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly

825191.0k1](/packages/daux-dauxio)[sspooky13/yaml-standards

Standards for yaml files

11518.3k3](/packages/sspooky13-yaml-standards)[prohalexey/the-choice

253.3k](/packages/prohalexey-the-choice)[opensoft/simple-serializer

Simple Serializer

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

PHPackages © 2026

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