New

The executive guide to generative AI

Read more

Implementing your own Serializer

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

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);


Was this helpful?
Feedback