* @package WB * @subpackage base */ WBClass::load( 'WBRest_Serializer' ); /** * REST Serializer / Unserializer JSON * * @version 0.2.0 * @package WB * @subpackage base */ class WBRest_Serializer_Json extends WBRest_Serializer { /** * format string of server error * * @var string */ protected $errorFrame = '{ "status": "error", "errors": [{ "code": "%d", "message": "%s" }] }'; /** * Unserialize Request * * Convert Request body to data array * * @param string $body * @param string name of data element, if any * @return array $data */ public function unserialize($body, $dataElement = 'data') { $body = trim($body); $all = json_decode($body, true); return $this->extractUnserializedElement($all, $dataElement); } /** * Serialize data * * Convert array data for response * * @param array $data * @return string $body */ public function serialize($data) { return json_encode($data) . "\n"; } }