Skip to content

Incorrect JSON-LD serialization when not in Node context #2034

@alxp

Description

@alxp

The Context Reactions that alter a node's JSON-LD representation depend on the Node Context being present.

If I go to http://localhost:8000/node/89?_format=jsonld

{
  "@graph": [
    {
      "@id": "http:\/\/localhost:8000\/node\/89",
      "@type": [
        "http:\/\/pcdm.org\/models#Object",
        "http:\/\/purl.org\/dc\/dcmitype\/Dataset"
      ],
      "http:\/\/schema.org\/dateModified": [
        {
          "@value": "2021-12-09T18:58:34+00:00",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#dateTime"
        }
      ],
      "http:\/\/purl.org\/spar\/datacite\/hasResourceType": [
        {
          "@value": "Visitations",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#string"
        }
      ],
      "http:\/\/purl.org\/spar\/datacite\/hasGeneralResourceTYpe": [
        {
          "@value": "Dataset",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#string",
          "@container": "@list"
        }
      ],
      "http:\/\/schema.org\/sameAs": [
        {
          "@id": "http:\/\/localhost:8000\/node\/89"
        }
      ]
    }
  ]
}

The "Dataset" type and the SameAs predicate were added via two context reactions that ship with Islandora, in JsonldSelfReferenceReaction.php and JsonldTypeAlterReaction.php.

However when I use Drupal's serializer service directly to get the node in JSON-LD format, I get:

$s = \Drupal::service('serializer);
$n = \Drupal::entityTypeManager()->getStorage('node')->load(89);
$s->serialize($n, 'jsonld');
<warning>PHP Deprecated:  \Drupal\node\Plugin\Condition\NodeType is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Entity\Plugin\Condition\EntityBundle instead. See https://www.drupal.org/node/2983299 in /var/www/html/drupal/web/core/modules/node/src/Plugin/Condition/NodeType.php on line 53</warning>
{
  "@graph": [
    {
      "@id": "http:\/\/default\/node\/89",
      "@type": [
        "http:\/\/pcdm.org\/models#Object"
      ],
      "http:\/\/schema.org\/dateModified": [
        {
          "@value": "2021-12-09T18:58:34+00:00",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#dateTime"
        }
      ],
      "http:\/\/purl.org\/spar\/datacite\/hasResourceType": [
        {
          "@value": "Visitations",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#string"
        }
      ],
      "http:\/\/purl.org\/spar\/datacite\/hasGeneralResourceTYpe": [
        {
          "@value": "Dataset",
          "@type": "http:\/\/www.w3.org\/2001\/XMLSchema#string",
          "@container": "@list"
        }
      ]
    }
  ]
}

Since the serializer service is pretty well-known, I think it's important to not have it generate different output depending on whether the node was loaded with a context or otherwise.

Generally I also don't think the added complexity gives us much that just writing a custom normalizer alter hook gives us.

I propose deprecating the JSONLD alter reactions and putting the Type based on field_external_uri value and "SameAs" predicates directly into the islandora module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: lowConsider using when the issue would enhance what is available to the community, but does not block pRepository:IslandoraIssues pertaining to the repository: https://github.com/Islandora/islandoraRepository:JsonLDIssues pertaining to the repository: https://github.com/Islandora/jsonldStaleSubject: Linked Datarelated to linked data. Consider also using metadata or modelling tags.Subject: Metadatarelated to metadata issues. Consider also using the search tag.Type: bugidentifies a problem in the software with clear steps to reproduceType: discussionIdentifies a topic for conversation - may be similar to a question.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions