src/Normalizer/EntityNormalizer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Normalizer/EntityNormalizer.php b/src/Normalizer/EntityNormalizer.php index 844a256..26ba08c 100644 --- a/src/Normalizer/EntityNormalizer.php +++ b/src/Normalizer/EntityNormalizer.php @@ -206,14 +206,20 @@ class EntityNormalizer extends NormalizerBase implements DenormalizerInterface { $fields = $entity->getFields(); } - // JSON API resource identifier objects are sufficient to identify entities, - // exposing an entity's ID (which is not a UUID) is bad, and exposing its - // bundle is useless (it's already part of the resource type name). + // JSON API resource identifier objects are sufficient to identify entities. + // By exposing all fields as attributes, we expose unwanted, confusing or + // duplicate information: + // - exposing an entity's ID (which is not a UUID) is bad + // - exposing its bundle is useless (it's already part of the resource type + // name) + // - exposing its UUID as an attribute is useless (it's already part of the + // mandatory "id" attribute in JSON API) // @see http://jsonapi.org/format/#document-resource-identifier-objects $id_field_name = $entity->getEntityType()->getKey('id'); unset($fields[$id_field_name]); $bundle_field_name = $entity->getEntityType()->getKey('bundle'); unset($fields[$bundle_field_name]); + unset($fields['uuid']); // Filter the array based on the field names. $enabled_field_names = array_filter(