diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 5447e90..b242ab4 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -332,14 +332,27 @@ protected function clearTranslationCache() {
   }
 
   /**
+   * Magic __sleep() implementation.
+   */
+  function __sleep() {
+    // Get the values of instantiated field objects, only serialize the values.
+    foreach ($this->fields as $name => $fields) {
+      foreach ($fields as $langcode => $field) {
+        $this->values[$name][$langcode] = $field->getValue();
+      }
+    }
+    $this->fields = array();
+    $this->fieldDefinitions = NULL;
+    $this->clearTranslationCache();
+    return array_keys(get_object_vars($this));
+  }
+
+
+  /**
    * Magic __wakeup() implementation.
    */
   public function __wakeup() {
     $this->init();
-    // @todo This should be done before serializing the entity, but we would
-    //   need to provide the full list of data to be serialized. See the
-    //   dedicated issue at https://drupal.org/node/2027795.
-    $this->clearTranslationCache();
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Field/ConfigEntityReferenceItemBase.php b/core/lib/Drupal/Core/Field/ConfigEntityReferenceItemBase.php
index b4c6720..e7b03af 100644
--- a/core/lib/Drupal/Core/Field/ConfigEntityReferenceItemBase.php
+++ b/core/lib/Drupal/Core/Field/ConfigEntityReferenceItemBase.php
@@ -106,6 +106,20 @@ public function isEmpty() {
 
   /**
    * {@inheritdoc}
+   */
+  public function getValue() {
+    $values = parent::getValue();
+
+    // If this item contains an entity that is not yet stored, return it as
+    // part of the field item values.
+    if (empty($this->target_id) && !empty($this->entity)) {
+      $values['entity'] = $this->entity;
+    }
+    return $values;
+  }
+
+  /**
+   * {@inheritdoc}
    *
    * Copied from \Drupal\field\Plugin\Field\FieldType\LegacyConfigFieldItem,
    * since we cannot extend it.
