src/ContentNegotiation/JmsSerializerContentNegotiation.php
public function createResponse($responseObject, $status = 200, array $headers = array())
    {
        $request = $this->app["request_stack"]->getCurrentRequest();
        $format = $request->getRequestFormat($this->app["conneg.defaultFormat"]);

        $serializedContent = $this->app["serializer"]->serialize(
            $responseObject,
            $format,
            $this->app["conneg.serializationContext"]
        );

        return new Response($serializedContent, $status, $headers);
    }
public function createResponse($responseObject, $status = 200, array $headers = array())
    {
        $request = $this->app["request_stack"]->getCurrentRequest();
        $format = $request->getRequestFormat($this->app["conneg.defaultFormat"]);

        $serializedContent = $this->app["serializer"]->serialize(
            $responseObject,
            $format,
            $this->app["conneg.serializationContext"]
        );

        return new Response($serializedContent, $status, $headers);
    }
This method can be used in place of Response::create to automatically serialize your response into the requested
format.

@param object $responseObject
@param int $status
@param array $headers
@return Response