Skip to content

Commit

Permalink
feat: Add support for @id and @type
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Sep 22, 2024
1 parent 7488ab5 commit aa8eba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/foundation/identity/jsonld/JsonLDKeywords.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class JsonLDKeywords {

public static final String JSONLD_TERM_AT_ID = "@id";
public static final String JSONLD_TERM_ID = "id";
public static final String JSONLD_TERM_AT_TYPE = "@type";
public static final String JSONLD_TERM_TYPE = "type";
}
16 changes: 12 additions & 4 deletions src/main/java/foundation/identity/jsonld/JsonLDObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,27 @@ public List<URI> getContexts() {
}

public final List<String> getTypes() {
return JsonLDUtils.jsonLdGetStringList(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE);
List<String> result = JsonLDUtils.jsonLdGetStringList(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_AT_TYPE);
if (result == null) result = JsonLDUtils.jsonLdGetStringList(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE);
return result;
}

public final String getType() {
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE);
String result = JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_AT_TYPE);
if (result == null) result = JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE);
return result;
}

public final boolean isType(String type) {
return JsonLDUtils.jsonLdContainsString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE, type);
boolean result = JsonLDUtils.jsonLdContainsString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_AT_TYPE, type);
if (! result) result = JsonLDUtils.jsonLdContainsString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_TYPE, type);
return result;
}

public final URI getId() {
return JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_ID));
URI result = JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_AT_ID));
if (result == null) result = JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), JsonLDKeywords.JSONLD_TERM_ID));
return result;
}

/*
Expand Down

0 comments on commit aa8eba0

Please sign in to comment.