diff --git a/core/core.services.yml b/core/core.services.yml
index 51ce4c4..954a801 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -118,7 +118,7 @@ services:
     arguments: ['@service_container', '@settings']
   keyvalue.database:
     class: Drupal\Core\KeyValueStore\KeyValueDatabaseFactory
-    arguments: ['@database']
+    arguments: ['@serialization.phpserialize', '@database']
   keyvalue.expirable:
     class: Drupal\Core\KeyValueStore\KeyValueExpirableFactory
     arguments: ['@service_container', '@settings']
@@ -127,6 +127,10 @@ services:
     tags:
       - { name: needs_destruction }
     arguments: ['@database']
+
+  serialization.phpserialize:
+    class: Drupal\Core\Serialization\PhpSerialize
+
   settings:
     class: Drupal\Component\Utility\Settings
     factory_class: Drupal\Component\Utility\Settings
diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
index 1464186..d25d2f3 100644
--- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
+++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
@@ -9,6 +9,7 @@
 
 use Drupal\Core\Database\Query\Merge;
 use Drupal\Core\Database\Connection;
+use Drupal\Core\Serialization\SerializationInterface;
 
 /**
  * Defines a default key/value store implementation.
@@ -19,6 +20,13 @@
 class DatabaseStorage extends StorageBase {
 
   /**
+   * The serialization class to use.
+   *
+   * @var \Drupal\Core\Serialization\SerializationInterface
+   */
+  protected $serializer;
+
+  /**
    * The database connection.
    *
    * @var \Drupal\Core\Database\Connection
@@ -37,11 +45,16 @@ class DatabaseStorage extends StorageBase {
    *
    * @param string $collection
    *   The name of the collection holding key and value pairs.
+   * @param \Drupal\Core\Serialization\SerializationInterface $serializer
+   *   The serialization class to use.
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The database connection to use.
    * @param string $table
    *   The name of the SQL table to use, defaults to key_value.
    */
-  public function __construct($collection, Connection $connection, $table = 'key_value') {
+  public function __construct($collection, SerializationInterface $serializer, Connection $connection, $table = 'key_value') {
     parent::__construct($collection);
+    $this->serializer = $serializer;
     $this->connection = $connection;
     $this->table = $table;
   }
@@ -65,7 +78,7 @@ public function getMultiple(array $keys) {
       $result = $this->connection->query('SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name IN (:keys) AND collection = :collection', array(':keys' => $keys, ':collection' => $this->collection))->fetchAllAssoc('name');
       foreach ($keys as $key) {
         if (isset($result[$key])) {
-          $values[$key] = unserialize($result[$key]->value);
+          $values[$key] = $this->serializer->decode($result[$key]->value);
         }
       }
     }
@@ -86,7 +99,7 @@ public function getAll() {
 
     foreach ($result as $item) {
       if ($item) {
-        $values[$item->name] = unserialize($item->value);
+        $values[$item->name] = $this->serializer->decode($item->value);
       }
     }
     return $values;
@@ -101,7 +114,7 @@ public function set($key, $value) {
         'name' => $key,
         'collection' => $this->collection,
       ))
-      ->fields(array('value' => serialize($value)))
+      ->fields(array('value' => $this->serializer->encode($value)))
       ->execute();
   }
 
@@ -113,7 +126,7 @@ public function setIfNotExists($key, $value) {
       ->insertFields(array(
         'collection' => $this->collection,
         'name' => $key,
-        'value' => serialize($value),
+        'value' => $this->serializer->encode($value),
       ))
       ->condition('collection', $this->collection)
       ->condition('name', $key)
diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
index fb0b8b0..7861b0c 100644
--- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
+++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
@@ -10,6 +10,7 @@
 use Drupal\Core\DestructableInterface;
 use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Query\Merge;
+use Drupal\Core\Serialization\PhpSerialize;
 
 /**
  * Defines a default key/value store implementation for expiring items.
@@ -20,13 +21,6 @@
 class DatabaseStorageExpirable extends DatabaseStorage implements KeyValueStoreExpirableInterface, DestructableInterface {
 
   /**
-   * The connection object for this storage.
-   *
-   * @var \Drupal\Core\Database\Connection
-   */
-  protected $connection;
-
-  /**
    * Flag indicating whether garbage collection should be performed.
    *
    * When this flag is TRUE, garbage collection happens at the end of the
@@ -53,7 +47,7 @@ class DatabaseStorageExpirable extends DatabaseStorage implements KeyValueStoreE
    *     key_value_expire.
    */
   public function __construct($collection, Connection $connection, $table = 'key_value_expire') {
-    parent::__construct($collection, $connection, $table);
+    parent::__construct($collection, new PhpSerialize(), $connection, $table);
   }
 
   /**
@@ -78,7 +72,7 @@ public function getMultiple(array $keys) {
         ':keys' => $keys,
         ':collection' => $this->collection,
       ))->fetchAllKeyed();
-    return array_map('unserialize', $values);
+    return array_map(array($this->serializer, 'decode'), $values);
   }
 
   /**
@@ -91,7 +85,7 @@ public function getAll() {
         ':collection' => $this->collection,
         ':now' => REQUEST_TIME
       ))->fetchAllKeyed();
-    return array_map('unserialize', $values);
+    return array_map(array($this->serializer, 'decode'), $values);
   }
 
   /**
@@ -107,7 +101,7 @@ function setWithExpire($key, $value, $expire) {
         'collection' => $this->collection,
       ))
       ->fields(array(
-        'value' => serialize($value),
+        'value' => $this->serializer->encode($value),
         'expire' => REQUEST_TIME + $expire,
       ))
       ->execute();
@@ -124,7 +118,7 @@ function setWithExpireIfNotExists($key, $value, $expire) {
       ->insertFields(array(
         'collection' => $this->collection,
         'name' => $key,
-        'value' => serialize($value),
+        'value' => $this->serializer->encode($value),
         'expire' => REQUEST_TIME + $expire,
       ))
       ->condition('collection', $this->collection)
diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php
index 1a840b3..43063ab 100644
--- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php
+++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php
@@ -6,8 +6,10 @@
  */
 
 namespace Drupal\Core\KeyValueStore;
+
 use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Database;
+use Drupal\Core\Serialization\SerializationInterface;
 
 /**
  * Defines the key/value store factory for the database backend.
@@ -15,13 +17,29 @@
 class KeyValueDatabaseFactory implements KeyValueFactoryInterface {
 
   /**
-   * Constructs this factory object.
+   * The serialization class to use.
+   *
+   * @var \Drupal\Core\Serialization\SerializationInterface
+   */
+  protected $serializer;
+
+  /**
+   * The database connection to use.
    *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * Constructs this factory object.
    *
+   * @param \Drupal\Core\Serialization\SerializationInterface $serializer
+   *   The serialization class to use.
    * @param \Drupal\Core\Database\Connection $connection
    *   The Connection object containing the key-value tables.
    */
-  function __construct(Connection $connection) {
+  function __construct(SerializationInterface $serializer, Connection $connection) {
+    $this->serializer = $serializer;
     $this->connection = $connection;
   }
 
@@ -29,6 +47,6 @@ function __construct(Connection $connection) {
    * {@inheritdoc}
    */
   public function get($collection) {
-    return new DatabaseStorage($collection, $this->connection);
+    return new DatabaseStorage($collection, $this->serializer, $this->connection);
   }
 }
diff --git a/core/lib/Drupal/Core/Serialization/Exception/InvalidDataTypeException.php b/core/lib/Drupal/Core/Serialization/Exception/InvalidDataTypeException.php
new file mode 100644
index 0000000..e6b8ce6
--- /dev/null
+++ b/core/lib/Drupal/Core/Serialization/Exception/InvalidDataTypeException.php
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Serialization\Exception\InvalidDataTypeException.
+ */
+
+namespace Drupal\Core\Serialization\Exception;
+
+/**
+ * Exception thrown when a data type is invalid.
+ */
+class InvalidDataTypeException extends \InvalidArgumentException {
+}
diff --git a/core/lib/Drupal/Core/Serialization/PhpSerialize.php b/core/lib/Drupal/Core/Serialization/PhpSerialize.php
new file mode 100644
index 0000000..4b912ba
--- /dev/null
+++ b/core/lib/Drupal/Core/Serialization/PhpSerialize.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Serialization\PhpSerialize.
+ */
+
+namespace Drupal\Core\Serialization;
+
+/**
+ * Default serialization for serialized PHP.
+ */
+class PhpSerialize implements SerializationInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function encode($data) {
+    return serialize($data);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function decode($raw) {
+    return unserialize($raw);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getFileExtension() {
+    return 'serialized';
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Serialization/SerializationInterface.php b/core/lib/Drupal/Core/Serialization/SerializationInterface.php
new file mode 100644
index 0000000..7713032
--- /dev/null
+++ b/core/lib/Drupal/Core/Serialization/SerializationInterface.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Serialization\SerializationInterface.
+ */
+
+namespace Drupal\Core\Serialization;
+
+/**
+ * Defines an interface for serialization formats.
+ */
+interface SerializationInterface {
+
+  /**
+   * Encodes data into the serialization format.
+   *
+   * @param mixed $data
+   *   The data to encode.
+   *
+   * @return string
+   *   The encoded data.
+   */
+  public static function encode($data);
+
+  /**
+   * Decodes data from the serialization format.
+   *
+   * @param string $raw
+   *   The raw data string to decode.
+   *
+   * @return mixed
+   *   The decoded data.
+   */
+  public static function decode($raw);
+
+  /**
+   * Returns the file extension for this serialization format.
+   *
+   * @return string
+   *   The file extension, without leading dot.
+   */
+  public static function getFileExtension();
+
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php
index ad286d6..3442530 100644
--- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php
@@ -34,7 +34,10 @@ protected function setUp() {
       ->addArgument('default');
     $this->container
       ->register('keyvalue.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseFactory')
+      ->addArgument(new Reference('serialization.phpserialize'))
       ->addArgument(new Reference('database'));
+    $this->container
+      ->register('serialization.phpserialize', 'Drupal\Core\Serialization\PhpSerialize');
     $this->settingsSet('keyvalue_default', 'keyvalue.database');
   }
 
