Implementing your own Serializer

edit

Implementing your own Serializer

edit

If you want to use your own custom serializer, you need to implement the SerializerInterface interface:

class MyCustomSerializer implements SerializerInterface
{

    /**
     * Serialize request body
     *
     * @param string|array $data Request body
     *
     * @return string
     */
    public function serialize($data)
    {
        // code here
    }

    /**
     * Deserialize response body
     *
     * @param string $data Response body
     * @param array  $headers Response Headers
     *
     * @return array|string
     */
    public function deserialize($data, $headers)
    {
        // code here
    }
}


To use it, you simply provide the class path in the configuration parameters:

$params['serializerClass'] = '\MyProject\Serializers\MyCustomSerializer';
$client = new Elasticsearch\Client($params);