IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Implementing your own Serializer
editImplementing your own Serializer
editIf you want to use your own custom serializer, you need to implement the SerializerInterface
interface. Please
keep in mind that the client uses a single Serializer object for all endpoints and all connections.
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 then use your custom serializer, you can specify the namespace path in the setSerializer()
method of the ClientBuilder
object:
$client = ClientBuilder::create() ->setSerializer('\MyProject\Serializers\MyCustomSerializer'); ->build();
Alternatively, if your serializer has a constructor or further initialization that should occur before given to the client, you can instantiate an object and provide that instead:
$mySerializer = new MyCustomSerializer($a, $b, $c); $mySerializer->setFoo("bar"); $client = ClientBuilder::create() ->setSerializer($mySerializer); ->build();