ttree/serializer

This package is abandoned and no longer maintained. No replacement package was suggested.

Package for TYPO3 Flow to convert PHP object to and from JSON

Installs: 141

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:typo3-flow-package

1.0.1 2014-11-07 17:04 UTC

This package is auto-updated.

Last update: 2019-01-25 15:36:20 UTC


README

Build Status Total Downloads

This package can be used to convert PHP object to and from JSON. The current version support object tree, but no circular references, as there is no way to represent this kind of reference in a JSON file.

Usage

Use DI to inject the Ttree\Serializer\SerializerInterface where you need it:

class ObjectUtility {

	/**
	 * @Flow\Inject
	 * @var \Ttree\Serializer\SerializerInterface
	 */
	protected $serializer;

	/**
	 * @param object $object
	 * @return string
	 */
	public function save($object) {
		$json = $this->serializer->serialize($object);
	}
	
	/**
	 * @param string $string
	 * @return object
	 */
	public function load($string) {
		$json = $this->serializer->unserialize($string);
	}

}

Skip property

The serializer will only include gettable properties. Transient property in a Doctrine entity are skipped automaticaly.

You can skip any property by using the Ttree\Serializer\Annotations\Skip.

Functional Programming

You can also use directly the objects Ttree\Serializer\Json\Serialize and Ttree\Serializer\Json\Serialize in a functionnal style programming:

$serialize = new Serialize();
$json = $serialize(array('Hello', 'World'));
$unserialize = new Unserialize();
$array = $unserialize('["Hello","World"]')