PHPackages                             kingson-de/marshal-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. kingson-de/marshal-serializer

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

kingson-de/marshal-serializer
=============================

Marshal is serializing / marshalling data structures to the desired format. It is also deserializing / unmarshalling the format back to the data structures.

v1.3.0(7y ago)274632Apache-2.0PHPPHP ^7.0

Since Nov 22Pushed 7y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (1)Versions (5)Used By (2)

Marshal Serializer
==================

[](#marshal-serializer)

[![Marshal Serializer logo](marshal.png "Marshal Serializer")](marshal.png)

[![License](https://camo.githubusercontent.com/a549a7a30bacba7bfceebdc207a8e86c3f2c02995a2527640dca30048fd2b64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667)](https://github.com/Kingson-de/marshal-serializer/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/de2916d4ed08ba148a3b39a6ab24f51993d315dec4899af116fa26c02064d426/68747470733a2f2f7472617669732d63692e6f72672f4b696e67736f6e2d64652f6d61727368616c2d73657269616c697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Kingson-de/marshal-serializer)[![Code Coverage](https://camo.githubusercontent.com/bee0660be2eb348389fef5b89ff6313f00f4ac8fe134618f06be0e92aa2e3344/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4b696e67736f6e2d64652f6d61727368616c2d73657269616c697a65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Kingson-de/marshal-serializer/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/74474a38159d2061a08e2087419bce76a213b0bbf606a0782f2458a651064ba0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4b696e67736f6e2d64652f6d61727368616c2d73657269616c697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Kingson-de/marshal-serializer/?branch=master)

Introduction
------------

[](#introduction)

Marshal is [serializing](https://en.wikipedia.org/wiki/Serialization) / [marshalling](https://en.wikipedia.org/wiki/Marshalling_(computer_science)) data structures to the desired format. It is also deserializing / unmarshalling the format back to the data structures.

Especially useful for building the raw response for web services which then can be formatted to JSON for example.

If you need to serialize directly to a format, use the appropriate Marshal library:

- [Marshal JSON serializer](https://github.com/Kingson-de/marshal-json-serializer)
- [Marshal XML serializer](https://github.com/Kingson-de/marshal-xml-serializer)

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

[](#installation)

Easiest way to install the library is via composer:

```
composer require kingson-de/marshal-serializer

```

The following PHP versions are supported:

- PHP 7.0
- PHP 7.1
- PHP 7.2
- PHP 7.3

Execute tests
-------------

[](#execute-tests)

Just run:

```
composer test

```

Or without code coverage:

```
composer quicktest

```

Usage
-----

[](#usage)

### Mappers

[](#mappers)

The first thing to do is to create a mapper that takes care of mapping your entities / models to the correct format.

You always need to inherit from the abstract Mapper class and implement a `map` function with your type hinting.

There is also the option to use directly a callable to map data. This will be explained later.

It is always possible to use a callable in a mapper or vice versa.

```
