Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alxp opened this issue Jan 18, 2022 · 0 comments
Open

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

alxp opened this issue Jan 18, 2022 · 0 comments
Labels
Priority: low Consider using when the issue would enhance what is available to the community, but does not block p Repository:Islandora Issues pertaining to the repository: https://github.com/Islandora/islandora Repository:JsonLD Issues pertaining to the repository: https://github.com/Islandora/jsonld Subject: Linked Data related to linked data. Consider also using metadata or modelling tags. Subject: Metadata related to metadata issues. Consider also using the search tag. Type: bug identifies a problem in the software with clear steps to reproduce Type: discussion Identifies a topic for conversation - may be similar to a question.

Comments

@alxp
Copy link
Contributor

alxp commented Jan 18, 2022

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.

@alxp alxp added Repository:Islandora Issues pertaining to the repository: https://github.com/Islandora/islandora Repository:JsonLD Issues pertaining to the repository: https://github.com/Islandora/jsonld Subject: Linked Data related to linked data. Consider also using metadata or modelling tags. Subject: Metadata related to metadata issues. Consider also using the search tag. Type: bug identifies a problem in the software with clear steps to reproduce Type: discussion Identifies a topic for conversation - may be similar to a question. labels Jan 18, 2022
@alxp alxp added the Priority: low Consider using when the issue would enhance what is available to the community, but does not block p label Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: low Consider using when the issue would enhance what is available to the community, but does not block p Repository:Islandora Issues pertaining to the repository: https://github.com/Islandora/islandora Repository:JsonLD Issues pertaining to the repository: https://github.com/Islandora/jsonld Subject: Linked Data related to linked data. Consider also using metadata or modelling tags. Subject: Metadata related to metadata issues. Consider also using the search tag. Type: bug identifies a problem in the software with clear steps to reproduce Type: discussion Identifies a topic for conversation - may be similar to a question.
Projects
Status: No status
Development

No branches or pull requests

1 participant