note 109425 added to class.jsonserializable
| From: | mindplay.dk | Date: | Mon, 16 Jul 2012 13:25:59 +0000 |
| Subject: | note 109425 added to class.jsonserializable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189156@lists.php.net to get a copy of this message | ||
Note that while the JsonSerializable interface enables you to serialize an object to a JSON
string-representation using json_encode(), there is currently no counterpart for de-serialization.
Also note that, by default, the class-name of the serialized object isn't stored, so
technically there would be no way to de-serialize an object-graph from a string-representation.
Although you could of course store the class-name by returning it via the JsonSerializable
interface, that still does not provide a mechanism for de-serialization.
I wrote the following class, which performs serialization and de-serialization in JSON format, by
storing the class-name in a reserved '#type' property in JSON objects:
http://github.com/mindplay-dk/jsonfreeze/blob/master/mindplay/jsonfreeze/JsonSerializer.php
This does have some limitations, which are discussed here:
http://stackoverflow.com/questions/10489876
----
Server IP: 69.147.83.197
Probable Submitter: 68.70.61.119
----
Manual Page -- http://www.php.net/manual/en/class.jsonserializable.php
Edit -- https://master.php.net/note/edit/109425
Del: integrated -- https://master.php.net/note/delete/109425/integrated
Del: useless -- https://master.php.net/note/delete/109425/useless
Del: bad code -- https://master.php.net/note/delete/109425/bad+code
Del: spam -- https://master.php.net/note/delete/109425/spam
Del: non-english -- https://master.php.net/note/delete/109425/non-english
Del: in docs -- https://master.php.net/note/delete/109425/in+docs
Del: other reasons-- https://master.php.net/note/delete/109425
Reject -- https://master.php.net/note/reject/109425
Search -- https://master.php.net/manage/user-notes.php