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

use try with resources in JSONLDUtil #9882

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading