 .../tests/modules/rest_test/rest_test.services.yml |  6 ++---
 .../src/EventSubscriber/FormatProvider.php         | 31 ----------------------
 .../rest_test/src/RestTestServiceProvider.php      | 22 +++++++++++++++
 3 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/core/modules/rest/tests/modules/rest_test/rest_test.services.yml b/core/modules/rest/tests/modules/rest_test/rest_test.services.yml
index 40b5002..87e47e8 100644
--- a/core/modules/rest/tests/modules/rest_test/rest_test.services.yml
+++ b/core/modules/rest/tests/modules/rest_test/rest_test.services.yml
@@ -1,5 +1,5 @@
 services:
-  rest_test.format_provider:
-    class: Drupal\rest_test\EventSubscriber\FormatProvider
+  serializer.encoder.foobar:
+    class: Drupal\serialization\Encoder\JsonEncoder
     tags:
-      - { name: event_subscriber }
+      - { name: encoder, format: foobar }
diff --git a/core/modules/rest/tests/modules/rest_test/src/EventSubscriber/FormatProvider.php b/core/modules/rest/tests/modules/rest_test/src/EventSubscriber/FormatProvider.php
deleted file mode 100644
index ac6f237..0000000
--- a/core/modules/rest/tests/modules/rest_test/src/EventSubscriber/FormatProvider.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-namespace Drupal\rest_test\EventSubscriber;
-
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-use Symfony\Component\HttpKernel\Event\GetResponseEvent;
-use Symfony\Component\HttpKernel\KernelEvents;
-
-/**
- * Event subscriber for adding additional content types to the request.
- */
-class FormatProvider implements EventSubscriberInterface {
-
-  /**
-   * Register content type formats on the request object.
-   *
-   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
-   *   The Event to process.
-   */
-  public function onKernelRequest(GetResponseEvent $event) {
-    $event->getRequest()->setFormat('foobar', ['text/foobar']);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  static function getSubscribedEvents() {
-    $events[KernelEvents::REQUEST][] = ['onKernelRequest'];
-    return $events;
-  }
-}
diff --git a/core/modules/rest/tests/modules/rest_test/src/RestTestServiceProvider.php b/core/modules/rest/tests/modules/rest_test/src/RestTestServiceProvider.php
index e69de29..7d3aeb4 100644
--- a/core/modules/rest/tests/modules/rest_test/src/RestTestServiceProvider.php
+++ b/core/modules/rest/tests/modules/rest_test/src/RestTestServiceProvider.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Drupal\rest_test;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceModifierInterface;
+
+/**
+ * Adds "foobar" as known format.
+ */
+class RestTestServiceProvider implements ServiceModifierInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function alter(ContainerBuilder $container) {
+    if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), '\Drupal\Core\StackMiddleware\NegotiationMiddleware', TRUE)) {
+      $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['foobar', ['text/foobar']]);
+    }
+  }
+
+}
