Skip to content

Commit

Permalink
Merge pull request #9882 from IQSS/9313-jsonld-try
Browse files Browse the repository at this point in the history
use try with resources in JSONLDUtil
  • Loading branch information
kcondon authored Sep 11, 2023
2 parents 62a9811 + 9c1819b commit 6fee8e5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import edu.harvard.iq.dataverse.DatasetVersion.VersionState;
import edu.harvard.iq.dataverse.license.License;
import edu.harvard.iq.dataverse.license.LicenseServiceBean;
import jakarta.json.JsonReader;

public class JSONLDUtil {

Expand Down Expand Up @@ -533,13 +534,11 @@ public static JsonObject decontextualizeJsonLD(String jsonLDString) {
try (StringReader rdr = new StringReader(jsonLDString)) {

// Use JsonLd to expand/compact to localContext
JsonObject jsonld = Json.createReader(rdr).readObject();
JsonDocument doc = JsonDocument.of(jsonld);
JsonArray array = null;
try {
array = JsonLd.expand(doc).get();
jsonld = JsonLd.compact(JsonDocument.of(array), JsonDocument.of(Json.createObjectBuilder().build()))
.get();
try (JsonReader jsonReader = Json.createReader(rdr)) {
JsonObject jsonld = jsonReader.readObject();
JsonDocument doc = JsonDocument.of(jsonld);
JsonArray array = JsonLd.expand(doc).get();
jsonld = JsonLd.compact(JsonDocument.of(array), JsonDocument.of(Json.createObjectBuilder().build())).get();
// jsonld = array.getJsonObject(0);
logger.fine("Decontextualized object: " + jsonld);
return jsonld;
Expand Down

0 comments on commit 6fee8e5

Please sign in to comment.