johyunchol/php-gson2

PHP GSON equivalent - simple entity mapper. JSON to object and object to JSON. from archangeldesign/php-gson

0.2.1 2021-03-09 10:04 UTC

This package is not auto-updated.

Last update: 2025-06-26 04:45:46 UTC


README

Build Status Coverage Status

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

Installation

composer require johyunchol/php-gson2

or download and include autoload.php

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

Usage

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

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

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

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