Description
Serializard is a library for (un)serialization of data of any complexity. Its main focus is to give user as much flexibility as possible by delegating the (un)serialization logic to the programmer to encourage good object design and only supervising the process hiding the unpleasant details about it.
Serializard alternatives and similar libraries
Based on the "Data Structure and Storage" category.
Alternatively, view Serializard alternatives based on common mentions on social networks and blogs.
-
Porter
:lipstick: Durable and asynchronous data imports for consuming data at scale and publishing testable SDKs. -
Cake Collection
[READ-ONLY] Collection library in CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp -
CRUDlex
CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Serializard or a related project?
README
Serializard
Serializard is a library for (un)serialization of data of any complexity. Its main focus is to give user as much flexibility as possible by delegating the (un)serialization logic to the programmer to encourage good object design and only supervising the process hiding the unpleasant details about it.
Installation
This library is available on Composer/Packagist as thunderer/serializard
.
Usage
Let's consider a simple User class with two properties and some setup code:
final class User
{
private $id;
private $name;
public function __construct(int $id, string $name) { /* ... */ }
public function getId() { return $this->id; }
public function getName() { return $this->name; }
}
$user = new User(1, 'Thomas');
$formats = new FormatContainer();
$formats->add('json', new JsonFormat());
$hydrators = new FallbackHydratorContainer();
$normalizers = new FallbackNormalizerContainer();
$serializard = new Serializard($formats, $normalizers, $hydrators);
Serialization
Serialization is controlled by registering handlers used in normalization phase:
$normalizers->add(User::class, function(User $user) {
return [
'id' => $user->getId(),
'name' => $user->getName(),
];
});
$result = $serializard->serialize($user, 'json');
// result is {"id":1,"name":"Thomas"}
Unserialization
Unserialization can be controlled by registering callables able to reconstruct objects from data parsed from input text:
$hydrators->add(User::class, function(array $data) {
return new User($data['id'], $data['name']);
});
$json = '{"id":1,"name":"Thomas"}';
$user = $serializard->unserialize($json, User::class, 'json');
Formats
- JSON in
JsonFormat
converts objects to JSON, - Array in
ArrayFormat
just returns object graph normalized to arrays of scalars, - YAML in
YamlFormat
converts objects to YAML (usessymfony/yaml
), - XML in
XmlFormat
converts objects to XML (usesext-dom
).
License
See LICENSE file in the main directory of this library.
*Note that all licence references and agreements mentioned in the Serializard README section above
are relevant to that project's source code only.