src/EventListener/ResponseListener.php
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof SerializedResponse) {
            $acceptableContentTypes = $event->getRequest()->getAcceptableContentTypes();

            $format = 'json';

            foreach ($acceptableContentTypes as $item) {
                if (strpos($item, 'xml') !== false) {
                    $format = 'xml';
                    break;
                }
            }

            $serializedData = $this->serializer->serialize($response->getData(), $format, null);

            $response->setContent($serializedData);
        }
    }
public function onKernelResponse(FilterResponseEvent $event)
    {
        $response = $event->getResponse();

        if ($response instanceof SerializedResponse) {
            $acceptableContentTypes = $event->getRequest()->getAcceptableContentTypes();

            $format = 'json';

            foreach ($acceptableContentTypes as $item) {
                if (strpos($item, 'xml') !== false) {
                    $format = 'xml';
                    break;
                }
            }

            $serializedData = $this->serializer->serialize($response->getData(), $format, null);

            $response->setContent($serializedData);
        }
    }
public function onKernelResponse ( FilterResponseEvent $ event ) { $ response = $ event -> getResponse ( ) ; if ( $ response instanceof SerializedResponse ) { $ acceptableContentTypes = $ event -> getRequest ( ) -> getAcceptableContentTypes ( ) ; $ format = 'json' ; foreach ( $ acceptableContentTypes as $ item ) { if ( strpos ( $ item , 'xml' ) !== false ) { $ format = 'xml' ; break ; } } $ serializedData = $ this -> serializer -> serialize ( $ response -> getData ( ) , $ format , null ) ; $ response -> setContent ( $ serializedData ) ; } }
Modify the Response given the Request if the Response is a instance of SerializedResponse.

@param FilterResponseEvent $event
Modify the Response given the Request if the Response is a instance of SerializedResponse .