PHP GSON equivalent - simple entity mapper. JSON to object and object to JSON

0.2 2019-07-25 18:05 UTC

This package is auto-updated.

Last update: 2024-04-29 02:30:07 UTC


README

Build Status Coverage Status

Zero dependency simple PHP entity mapper. JSON String to Objcet and Object to JSON String.

Installation

composer require archangeldesign/php-gson

or download and include autoload.php

include 'php-gson/src/PHPGson/autoload.php';

Usage

Without instance. Object will be created using given class name.

$complexObject = null;
$success = \PHPGson\Gson::fromJson(
    $complexObject,
    '{"age":35, "hydratorTestObject":{"username":"raff"}}',
    \PHPGson\Extractor::EXTRACTION_MODE_METHOD,
    ComplexHydrationObject::class
);

With manual instantiation. Sub-objects will be created automatically in both cases.

$complexObject = new ComplexHydrationObject();
$success = \PHPGson\Gson::fromJson(
    $complexObject,
    '{"age":35, "hydratorTestObject":{"username":"raff"}}'
);
$object = new MainObject();
$jsonString = Gson::toJson($object);