decentralized-identity / jsonld-common-java

Shared JSON-LD Java library.
Apache License 2.0
7 stars 6 forks source link

Add support of @type #13

Open robertschubert opened 1 month ago

robertschubert commented 1 month ago

I am using the verifiable-credentials-java module.

When executing credential.getCredentialSubject().getTypes() the method returns the values of the field with the name type in the credentialSubject.

Looking into the code obviously the type is returned in JsonLDObject:

public final String getType() {
        return JsonLDUtils.jsonLdGetString(this.getJsonObject(), "type");
    }

I have a json object defined like this:

{
    "@context": {
      "xsd": "http://www.w3.org/2001/XMLSchema#",
    },
    "@id": "my-id",
    "@type": "my-type",

When I understood it right, @type is a keyword in JSON-LD used to set the type of an object, while type is a term that is defined by the @context and its meaning it can vary based on the context.

In the current implementation I cannot get the @type since only type is processed.

Can you add support for @type in the JsonLDObject?

robertschubert commented 1 month ago

BTW: workaround for me as user of that library is to call credential.getCredentialSubject().getJsonObject() and then get @type from the map.

peacekeeper commented 1 month ago

When I understood it right, @type is a keyword in JSON-LD used to set the type of an object, while type is a term that is defined by the @context and its meaning it can vary based on the context.

@robertschubert You are correct about this from a pure JSON-LD perspective. However, the W3C VCDM specification is clear that it uses type, not @type. See here and here.

Therefore I think our implementation should not support a dedicated call to get @type, and if you really need that, you coud use the workaround you mention.

Do you agree, or do you see that differently?

robertschubert commented 1 month ago

Hi @peacekeeper thanks for your answer. I can live with the workaround.

But: When going through both links you provided there is a note in both (just ctrl - f "@type"):

NOTE: The Verifiable Credentials Data Model is based on JSON-LD The type system for the Verifiable Credentials Data Model is the same as for [JSON-LD11] and is detailed in Section 3.5: Specifying the Type and Section 9: JSON-LD Grammar. When using a JSON-LD context (see Section 5.2 Extensibility), this specification aliases the @type keyword to type to make the JSON-LD documents more easily understood. While application developers and document authors do not need to understand the specifics of the JSON-LD type system, implementers of this specification who want to support interoperable extensibility, do.

If I understand it correctly an implementation should alias the @type to type. So I guess it should be supported from a specification point of view.