 jsonapi.services.yml                               |  24 +++--
 src/Controller/RequestHandler.php                  |   2 +-
 .../RegisterNormalizerClassesCompilerPass.php      |  37 ++++++++
 src/JsonapiServiceProvider.php                     |  11 ++-
 .../Functional/RestJsonApiFormatUnsupported.php    | 100 +++++++++++++++++++++
 .../JsonApiDocumentTopLevelNormalizerTest.php      |   4 +-
 6 files changed, 169 insertions(+), 9 deletions(-)

diff --git a/jsonapi.services.yml b/jsonapi.services.yml
index c111a8e..ecd6c36 100644
--- a/jsonapi.services.yml
+++ b/jsonapi.services.yml
@@ -56,10 +56,6 @@ services:
     arguments: ['@jsonapi.link_manager', '@entity_field.manager', '@plugin.manager.field.field_type', '@jsonapi.resource_type.repository', '@entity.repository']
     tags:
       - { name: normalizer, priority: 31 }
-  serializer.encoder.jsonapi:
-    class: Drupal\jsonapi\Encoder\JsonEncoder
-    tags:
-      - { name: encoder, priority: 21, format: 'api_json' }
   jsonapi.resource_type.repository:
     class: Drupal\jsonapi\ResourceType\ResourceTypeRepository
     arguments: ['@entity_type.manager', '@entity_type.bundle.info']
@@ -100,4 +96,22 @@ services:
     class: Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber
     tags:
       - { name: event_subscriber }
-    arguments: ['@serializer', '%serializer.formats%']
+    arguments: ['@jsonapi.serializer', '%serializer.formats%']
+
+  # We want the 'api_json' format to not be supported in the REST module, so we
+  # cannot register its encoder with the Serialization module. Hence we have an
+  # encoder without the 'encoder' tag and 'format' property. But that also
+  # means we cannot reuse the @serializer service. So we define our own
+  # serializer service. But we still do want to reuse the generic normalizers
+  # from the Serialization module. So we inject all normalizers just like the
+  # default @serializer service does. Only appropriate normalizers are called
+  # thanks to the supportsNormalization() API method.
+  # @see \Drupal\jsonapi\DependencyInjection\Compiler\RegisterNormalizerClassesCompilerPass
+  # @see \Drupal\jsonapi\JsonapiServiceProvider::register()
+  # @see \Drupal\Tests\jsonapi\Functional\RestJsonApiUnsupported
+  # @see \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization
+  jsonapi.serializer:
+    class: Symfony\Component\Serializer\Serializer
+    arguments: [{  }, ['@serializer.encoder.jsonapi']]
+  serializer.encoder.jsonapi:
+    class: Drupal\jsonapi\Encoder\JsonEncoder
diff --git a/src/Controller/RequestHandler.php b/src/Controller/RequestHandler.php
index 4c4fb5a..410529d 100644
--- a/src/Controller/RequestHandler.php
+++ b/src/Controller/RequestHandler.php
@@ -54,7 +54,7 @@ class RequestHandler implements ContainerAwareInterface, ContainerInjectionInter
 
     // Deserialize incoming data if available.
     /* @var \Symfony\Component\Serializer\SerializerInterface $serializer */
-    $serializer = $this->container->get('serializer');
+    $serializer = $this->container->get('jsonapi.serializer');
     /* @var \Drupal\jsonapi\Context\CurrentContext $current_context */
     $current_context = $this->container->get('jsonapi.current_context');
     $unserialized = $this->deserializeBody($request, $serializer, $route->getOption('serialization_class'), $current_context);
diff --git a/src/DependencyInjection/Compiler/RegisterNormalizerClassesCompilerPass.php b/src/DependencyInjection/Compiler/RegisterNormalizerClassesCompilerPass.php
new file mode 100644
index 0000000..32b5394
--- /dev/null
+++ b/src/DependencyInjection/Compiler/RegisterNormalizerClassesCompilerPass.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\jsonapi\DependencyInjection\Compiler;
+
+use Drupal\serialization\RegisterSerializationClassesCompilerPass;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
+/**
+ * Adds services tagged 'normalizer' to the JSON API Serializer.
+ *
+ * @see \Drupal\serialization\RegisterSerializationClassesCompilerPass
+ */
+class RegisterNormalizerClassesCompilerPass extends RegisterSerializationClassesCompilerPass  {
+
+  /**
+   * Adds services to the Serializer.
+   *
+   * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
+   *   The container to process.
+   */
+  public function process(ContainerBuilder $container) {
+    $definition = $container->getDefinition('jsonapi.serializer');
+
+    // Retrieve registered Normalizers from the container.
+    foreach ($container->findTaggedServiceIds('normalizer') as $id => $attributes) {
+      $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
+      $normalizers[$priority][] = new Reference($id);
+    }
+
+    // Add the registered Normalizers to the JSON API Serializer.
+    if (!empty($normalizers)) {
+      $definition->replaceArgument(0, $this->sort($normalizers));
+    }
+  }
+
+}
diff --git a/src/JsonapiServiceProvider.php b/src/JsonapiServiceProvider.php
index b5f9ea9..349af52 100644
--- a/src/JsonapiServiceProvider.php
+++ b/src/JsonapiServiceProvider.php
@@ -4,13 +4,15 @@ namespace Drupal\jsonapi;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
+use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+use Drupal\jsonapi\DependencyInjection\Compiler\RegisterNormalizerClassesCompilerPass;
 
 /**
  * Adds api_json as known format.
  *
  * @internal
  */
-class JsonapiServiceProvider implements ServiceModifierInterface {
+class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProviderInterface  {
 
   /**
    * {@inheritdoc}
@@ -28,4 +30,11 @@ class JsonapiServiceProvider implements ServiceModifierInterface {
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function register(ContainerBuilder $container) {
+    $container->addCompilerPass(new RegisterNormalizerClassesCompilerPass());
+  }
+
 }
diff --git a/tests/src/Functional/RestJsonApiFormatUnsupported.php b/tests/src/Functional/RestJsonApiFormatUnsupported.php
new file mode 100644
index 0000000..1c7d783
--- /dev/null
+++ b/tests/src/Functional/RestJsonApiFormatUnsupported.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace Drupal\Tests\jsonapi\Functional;
+
+use Drupal\Component\Serialization\Json;
+use Drupal\Core\Url;
+use Drupal\node\Entity\Node;
+use Drupal\node\Entity\NodeType;
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+use Drupal\Tests\rest\Functional\ResourceTestBase;
+
+/**
+ * @group jsonapi
+ */
+class RestJsonApiFormatUnsupported extends ResourceTestBase {
+
+  use AnonResourceTestTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['jsonapi', 'node'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $format = 'api_json';
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $mimeType = 'application/vnd.api+json';
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUpAuthorization($method) {
+    $this->grantPermissionsToTestedRole(['access content']);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+
+    // Set up a HTTP client that accepts relative URLs.
+    $this->httpClient = $this->container->get('http_client_factory')
+      ->fromOptions(['base_uri' => $this->baseUrl]);
+
+    // Create a "Camelids" node type.
+    NodeType::create([
+      'name' => 'Camelids',
+      'type' => 'camelids',
+    ])->save();
+
+    // Create a "Llama" node.
+    $node = Node::create(['type' => 'camelids']);
+    $node->setTitle('Llama')
+      ->setOwnerId(0)
+      ->setPublished(TRUE)
+      ->save();
+  }
+
+  /**
+   * Tests that JSON API is not supported
+   */
+  public function testJsonApiFormatNotSupportedInRest() {
+    // First, verify that 'api_json' does not appear in the 'serializer.foramts'
+    // container parameter, which is what the REST module uses to determine
+    // which formats it supports.
+    $this->assertSame(['json', 'xml'], $this->container->getParameter('serializer.formats'));
+
+    // Second, verify that provisioning a REST resource that lists 'api_json' as
+    // one of its formats
+    $this->provisionResource('entity.node', ['api_json'], []);
+    $this->setUpAuthorization('GET');
+    $url = Node::load(1)->toUrl()->setOption('query', ['_format' => 'api_json']);
+    $response = $this->request('GET', $url, []);
+    $expected_body = Json::encode([
+      'errors' => [
+        [
+          'title' => 'Not Acceptable',
+          'status' => 406,
+          'detail' => 'Not acceptable format: api_json',
+          'links' => [
+            'info' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7',
+          ],
+          'code' => 0,
+        ],
+      ],
+    ]);
+    $this->assertResourceResponse(406, $expected_body, $response);
+  }
+
+  protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {}
+  protected function getExpectedUnauthorizedAccessMessage($method) {}
+  protected function getExpectedBcUnauthorizedAccessMessage($method) {}
+
+}
diff --git a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
index 1238874..16dd793 100644
--- a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
+++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
@@ -339,7 +339,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase {
     $response = new ResourceResponse();
     $normalized = $this
       ->container
-      ->get('serializer')
+      ->get('jsonapi.serializer')
       ->serialize(
         new BadRequestHttpException('Lorem'),
         'api_json',
@@ -572,7 +572,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase {
     $request_stack = $this->container->get('request_stack');
     $request_stack->push($request);
     $this->container->set('request_stack', $request_stack);
-    $this->container->get('serializer');
+    $this->container->get('jsonapi.serializer');
 
     return [$request, $resource_type];
   }
