2017 © Pedro Peláez
 

library kayo-json-mapper

Map JSON data to PHP objects

image

tsufeki/kayo-json-mapper

Map JSON data to PHP objects

  • Tuesday, April 17, 2018
  • by tsufeki
  • Repository
  • 1 Watchers
  • 0 Stars
  • 388 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 20 % Grown

The README.md

Kayo JSON mapper

Build Status, (*1)

Map JSON data to PHP objects and back. No custom annotations needed., (*2)

Installation

With Composer:, (*3)

$ composer require tsufeki/kayo-json-mapper

Usage

use Tsufeki\KayoJsonMapper\MapperBuilder;

$mapper = MapperBuilder::create()
    ->getMapper();

$serialized = '{"foo": [1, 2], "bar": "baz"}';

// Pass data and the expected type:
$object = $mapper->load(json_decode($serialized), AClass::class);

$serialized2 = json_encode($mapper->dump($object));

Configuration

Kayo is designed to load/dump data without the need for special per class configuration such as annotations etc. All necessary information is gathered from reflection and doc comments., (*4)

However, its general behaviour can be customized in many ways through MapperBuilder methods., (*5)

Types & loading

All types recognized by phpDocumentor can be loaded, even union type (A|B) -- but please note that objects are differentiated on their shape (i.e. properties) so throwOnMissingProperty(true) and throwOnUnknownProperty(true) are usually necessary., (*6)

License

MIT - see LICENCE., (*7)

The Versions

25/12 2017
20/12 2017
19/12 2017