diff --git a/src/Entity/ExternalEntity.php b/src/Entity/ExternalEntity.php
index edb55fb..df0ed23 100644
--- a/src/Entity/ExternalEntity.php
+++ b/src/Entity/ExternalEntity.php
@@ -152,14 +152,22 @@ class ExternalEntity extends ContentEntityBase implements ExternalEntityInterfac
       $settings = $field_definition->getSettings();
       $property = $field_definition->getFieldStorageDefinition()->getMainPropertyName();
 
+      $offset = 0;
       // Special case for references to external entities.
       if (isset($settings['target_type']) && $settings['target_type'] === 'external_entity') {
         // Only 1 bundle is allowed.
         $target_bundle = reset($settings['handler_settings']['target_bundles']);
-        $object->{$destination} = substr($this->get($source)->{$property}, strlen($target_bundle) + 1);
+        $offset = strlen($target_bundle) + 1;
+      }
+      if ($this->get($source)->count() > 1) {
+        $values = $this->get($source)->getValue();
+        $object->{$destination} = [];
+        foreach ($values as $value_row) {
+          $object->{$destination}[] = substr($value_row[$property], $offset);
+        }
       }
       else {
-        $object->{$destination} = $this->get($source)->{$property};
+        $object->{$destination} = substr($this->get($source)->{$property}, $offset);
       }
     }
     return $object;
@@ -168,7 +176,9 @@ class ExternalEntity extends ContentEntityBase implements ExternalEntityInterfac
   /**
    * {@inheritdoc}
    */
-  public function mapObject(\stdClass $object) {
+  public function mapObject(\stdClass $obj) {
+    // Don't touch the original object.
+    $object = clone $obj;
     $bundle = $this->entityManager()->getStorage('external_entity_type')->load($this->bundle());
 
     foreach ($bundle->getFieldMappings() as $destination => $source) {
@@ -176,15 +186,32 @@ class ExternalEntity extends ContentEntityBase implements ExternalEntityInterfac
       $settings = $field_definition->getSettings();
       $property = $field_definition->getFieldStorageDefinition()->getMainPropertyName();
 
+      $value_prefix = '';
       // Special case for references to external entities.
       if (isset($settings['target_type']) && $settings['target_type'] === 'external_entity') {
         // Only 1 bundle is allowed.
         $target_bundle = reset($settings['handler_settings']['target_bundles']);
-        $this->get($destination)->{$property} = $target_bundle . '-' . $object->{$source};
+        $value_prefix = $target_bundle . '-';
       }
-      else {
-        $this->get($destination)->{$property} = $object->{$source};
+      // Array of value for the entity.
+      $destination_value = [];
+      // Set at least an empty string for the destination.
+      $object->{$source} = isset($object->{$source}) ? $object->{$source} : '';
+      // Convert to array.
+      if (!is_array($object->{$source})) {
+        $object->{$source} = [$object->{$source}];
+      }
+      foreach ($object->{$source} as $value) {
+        // For array cases we assume the property keys arrive from the client
+        // correctly.
+        if (is_array($value)) {
+          $destination_value[] = $value;
+        }
+        else {
+          $destination_value[] = [$property => $value_prefix . $value];
+        }
       }
+      $this->set($destination, $destination_value);
     }
     return $this;
   }
diff --git a/tests/src/Kernel/ExternalEntityTest.php b/tests/src/Kernel/ExternalEntityTest.php
new file mode 100644
index 0000000..3e0287e
--- /dev/null
+++ b/tests/src/Kernel/ExternalEntityTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\Tests\external_entities\Kernel;
+
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\external_entities\Entity\ExternalEntity;
+use Drupal\external_entities\Entity\ExternalEntityType;
+
+/**
+ * Tests the external entity methods.
+ *
+ * @group external_entities
+ */
+class ExternalEntityTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'field', 'external_entities'];
+
+  /**
+   * TODO: Remove when schema is fixed. https://www.drupal.org/node/2822381.
+   *
+   * @var bool
+   */
+  protected $strictConfigSchema = FALSE;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    ExternalEntityType::create([
+      'type' => 'test',
+      'field_mappings' => [
+        'id' => 'test_id',
+        'title' => 'test_name',
+      ],
+    ])->save();
+  }
+
+  /**
+   * Tests the mapping functions.
+   */
+  public function testMappings() {
+    $externalEntity = ExternalEntity::create(['type' => 'test']);
+    $object = new \stdClass();
+    $object->test_id = $this->randomString();
+    $object->test_name = $this->randomString();
+
+    // Map the object to the entity.
+    $externalEntity->mapObject($object);
+    // Get back the object.
+    $mappedObject = $externalEntity->getMappedObject();
+
+    // The retrieved object and our original object should be the same.
+    $this->assertEquals($object, $mappedObject);
+  }
+
+}
