2017 © Pedro Peláez
 

library json-resolver

A simple tool to resolve objects / trees of objects when encoding / decoding json

image

gries/json-resolver

A simple tool to resolve objects / trees of objects when encoding / decoding json

  • Monday, April 9, 2018
  • by gries
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5,146 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

JsonResolver

JsonResolver is a simple class that enables you to recursively encode / decode a tree of objects to json without having to deal with stdClasses., (*1)

This is being achieved by simply injecting the original class into the json as "json_resolve_class" property., (*2)

Installation

JsonResolver can be installed via. composer:, (*3)

{
    "require": {
        "gries/json-resolver": "dev-master"
    },
}

Usage

Every plain php object is supported the only requirement is that \JsonSerializeable is implemented., (*4)

Current features: - automatically decodes objects back to their previous classes. - automatically decodes related objects back to their previous classes if they implement the \JsonSerializeable interface. - automatically decodes arrays / traversable related objects if their values implement the \JsonSerializeable interface. - has a fallback method for objects that have not been previously encoded with the JsonResolver, (*5)

example usage

<?php

$book = new Book(); // JsonSerializeable
$author = new Author(); // JsonSerializeable
$author->addBook($book);    // author has a property books that is a array or TraversableInterface

$resolver = new JsonResolver();

$json = $resolver->encode($author);
$author = $resolver->decode($json);

get_class($author); // Author
get_class($author->getBooks()->getFirst()); // Book

For further examples see the examples section., (*6)

The Versions

09/04 2018

dev-master

9999999-dev

A simple tool to resolve objects / trees of objects when encoding / decoding json

  Sources   Download

MIT

The Development Requires

by Christoph Rosse

json

09/04 2018

0.0.3

0.0.3.0

A simple tool to resolve objects / trees of objects when encoding / decoding json

  Sources   Download

MIT

The Development Requires

by Christoph Rosse

json

24/11 2014

0.0.1

0.0.1.0

A simple tool to resolve objects / trees of objects when encoding / decoding json

  Sources   Download

MIT

The Development Requires

by Christoph Rosse

json

24/11 2014

0.0.2

0.0.2.0

A simple tool to resolve objects / trees of objects when encoding / decoding json

  Sources   Download

MIT

The Development Requires

by Christoph Rosse

json