From 6c6cdc6fa15198315b32d1d51ce8f80ab0a9cf72 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 2 Oct 2024 01:51:30 +0200 Subject: [PATCH] fix (core): Fix subtle bug in WritableResourceRDFHandler which appeared during RDF4j 5.0.1 to 5.0.2 upgrade Related to https://github.com/eclipse-rdf4j/rdf4j/pull/5096. --- java/dev/enola/core/rosetta/RosettaTest.java | 11 +++++++++++ java/dev/enola/rdf/io/WritableResourceRDFHandler.java | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/java/dev/enola/core/rosetta/RosettaTest.java b/java/dev/enola/core/rosetta/RosettaTest.java index 8ac09f24..3938adf7 100644 --- a/java/dev/enola/core/rosetta/RosettaTest.java +++ b/java/dev/enola/core/rosetta/RosettaTest.java @@ -33,6 +33,7 @@ import dev.enola.common.io.resource.MemoryResource; import dev.enola.common.io.resource.ResourceProvider; import dev.enola.common.io.resource.StringResource; +import dev.enola.common.yamljson.JSON; import dev.enola.rdf.io.RdfLoader; import dev.enola.rdf.io.RdfMediaTypes; import dev.enola.thing.Thing; @@ -134,6 +135,16 @@ public void testJsonToTurtle() throws Exception { assertThat(out.charSource().read()).contains("firstName> \"Salvador\""); } + @Test + public void testJsonToJsonld() throws Exception { + var in = rp.get("classpath:/picasso.json?context=classpath:/picasso-context.jsonld"); + var out = new MemoryResource(RdfMediaTypes.JSON_LD); + rosetta.convertInto(in, out); + // This is to detect invalid JSON, which happened during the RDF4j 5.0.1 to 5.0.2 upgrade + JSON.readObject(out.charSource().read()); + assertThat(out.charSource().read()).contains("firstName"); + } + @Test public void testYamlToTurtle() throws Exception { var in = rp.get("classpath:/picasso.yaml?context=classpath:/picasso-context.jsonld"); diff --git a/java/dev/enola/rdf/io/WritableResourceRDFHandler.java b/java/dev/enola/rdf/io/WritableResourceRDFHandler.java index a83bb88e..5ddf7f9b 100644 --- a/java/dev/enola/rdf/io/WritableResourceRDFHandler.java +++ b/java/dev/enola/rdf/io/WritableResourceRDFHandler.java @@ -67,7 +67,7 @@ private WritableResourceRDFHandler(RDFWriter rdfWriter, Writer ioWriter) @Override public void close() throws IOException { - endRDF(); + rdfWriter.endRDF(); ioWriter.close(); } @@ -78,7 +78,7 @@ public void startRDF() throws RDFHandlerException { @Override public void endRDF() throws RDFHandlerException { - rdfWriter.endRDF(); + // SUPPRESS rdfWriter.endRDF(); } @Override