diff --git a/core/modules/hal/src/Normalizer/FieldItemNormalizer.php b/core/modules/hal/src/Normalizer/FieldItemNormalizer.php index 5ad472a..7ff11dd 100644 --- a/core/modules/hal/src/Normalizer/FieldItemNormalizer.php +++ b/core/modules/hal/src/Normalizer/FieldItemNormalizer.php @@ -22,8 +22,10 @@ class FieldItemNormalizer extends NormalizerBase { */ public function normalize($field_item, $format = NULL, array $context = array()) { $values = []; + /** @var \Drupal\Core\TypedData\TypedDataInterface $data_item */ foreach ($field_item as $property => $data_item) { - $values[$property] = $this->serializer->normalize($data_item, $format, $context); + // @todo Support nullable types on the lowest levels. + $values[$property] = $data_item->getValue() === NULL ? NULL : $this->serializer->normalize($data_item, $format, $context); } if (isset($context['langcode'])) { diff --git a/core/modules/rest/src/Tests/PageCacheTest.php b/core/modules/rest/src/Tests/PageCacheTest.php index 66e57f5..37e7273 100644 --- a/core/modules/rest/src/Tests/PageCacheTest.php +++ b/core/modules/rest/src/Tests/PageCacheTest.php @@ -56,6 +56,7 @@ public function testConfigChangePageCache() { $entity = $this->entityCreate('entity_test'); $entity->set('field_test_text', 'custom cache tag value'); $serialized = $this->serializer->serialize($entity, $this->defaultFormat); + // Log in for creating the entity. $this->drupalLogin($account); $this->httpRequest('entity/entity_test', 'POST', $serialized, $this->defaultMimeType); diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php index 287c2df..20397ce 100644 --- a/core/modules/rest/src/Tests/UpdateTest.php +++ b/core/modules/rest/src/Tests/UpdateTest.php @@ -292,6 +292,7 @@ public function testUpdateComment() { $this->pass('Test case 1: PATCH comment using HAL+JSON.'); $comment->setSubject('Initial subject')->save(); $read_only_fields = [ + 'cid', 'status', 'name', 'created', @@ -304,13 +305,14 @@ public function testUpdateComment() { ]; $this->assertNotEqual('Updated subject', $comment->getSubject()); $comment->setSubject('Updated subject'); - $this->patchEntity($comment, $read_only_fields, $account, 'hal_json', 'application/hal+json'); + $this->patchEntity(clone $comment, $read_only_fields, $account, 'hal_json', 'application/hal+json'); $comment = Comment::load($comment->id()); $this->assertEqual('Updated subject', $comment->getSubject()); $this->pass('Test case 1: PATCH comment using JSON.'); $comment->setSubject('Initial subject')->save(); $read_only_fields = [ + 'cid', 'status', 'pid', // Extra compared to HAL+JSON. 'entity_id', @@ -325,7 +327,7 @@ public function testUpdateComment() { ]; $this->assertNotEqual('Updated subject', $comment->getSubject()); $comment->setSubject('Updated subject'); - $this->patchEntity($comment, $read_only_fields, $account, 'json', 'application/json'); + $this->patchEntity(clone $comment, $read_only_fields, $account, 'json', 'application/json'); $comment = Comment::load($comment->id()); $this->assertEqual('Updated subject', $comment->getSubject()); } diff --git a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php index 5062738..fd170dc 100644 --- a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php +++ b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php @@ -26,8 +26,10 @@ class ComplexDataNormalizer extends NormalizerBase { */ public function normalize($object, $format = NULL, array $context = array()) { $attributes = array(); + /** @var \Drupal\Core\TypedData\TypedDataInterface $field */ foreach ($object as $name => $field) { - $attributes[$name] = $this->serializer->normalize($field, $format, $context); + // @todo Support nullable types on the lowest levels. + $attributes[$name] = $field->getValue() === NULL ? NULL : $this->serializer->normalize($field, $format, $context); } return $attributes; }