1

I've seen the answer on How to return SPARQL results in JSON-LD?, but it's not satisfying/working. I used the JSON-LD Java Integration for Sesame, as well as the standalone version.

What I want to achieve: Send a SPARQL CONSTRUCT query to a SPARQL endpoint via Blazegraph RemoteRepository (based on Sesame/SAIL), get an RDF result, serialize that RDF to JSON-LD. The RDF result works perfectly fine.

The problem is, that the following code (with Sesame) is producing exactly no output:

StringWriter sw = new StringWriter();
final RDFWriter writer = Rio.createWriter( RDFFormat.JSONLD, sw );
//writer.getWriterConfig().set( JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT );
GraphQueryResult queryResults;
Rio.write(QueryResults.asModel(queryResults), writer);

I also used a conversion to a Jena internal model, because I know that the Jena JSON-LD output worked fine in another side project of mine. Unfortunately, the same approach doesn't work for a conversion to Jena.

My code with a Sesame to Jena Adapter:

while(queryResults.hasNext()) {
    JenaUtils.asJenaStatement();
}
StringWriter sw = new StringWriter();
// JenaUtils.getModel() returns the Jena model with the added statements above
RDFDataMgr.write( sw, JenaUtils.getModel(), RDFFormat.JSONLD );

What can I do now?

Community
  • 1
  • 1
mchlfchr
  • 3,998
  • 4
  • 26
  • 35
  • There is not enough information here to answer this, but the problem is at your end, not Sesame's or Jena's. Running your Sesame code, I can not reproduce this issue: when I create a non-empty `GraphQueryResult` and run it through your code, outputting to System.out (instead of using a StringWriter), I get output just fine. So either the problem is in how you obtain the `GraphQueryResult` (are you sure it's not empty?), or it's in what you do with the the `StringWriter` afterwards. – Jeen Broekstra Aug 20 '15 at 04:08
  • Looks like I was a bit premature to state it's "at your end". Thanks for providing the answer, useful to know about this library incompatibility. – Jeen Broekstra Aug 20 '15 at 20:43

1 Answers1

1

Ok, the problem was not my process mentioned above.

The issue was caused due to a supressed exception in the json-ld Sesame integration library by an incompatible version of the HTTP Client in Blazegraph.

java.lang.NoClassDefFoundError: org/apache/http/impl/client/SystemDefaultHttpClient

resulted in not piping the GraphQueryResults to the json-ld. The exception happened due to Blazegraph's incompatible HTTP Client Version (4.1.3), which overrode the json-ld HTTP Client Version (>4.1.3).

You have to override your project's dependency on HTTP Client with the following:

<!-- necessary for (sesame) json-ld integration, -->
<!-- because BlazeGraph uses an older version. See https://github.com/jsonld-java/jsonld-java/issues/64 -->
  <dependency>
     <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpclient</artifactId>
     <version>4.4</version>
  </dependency>

I hope that will safe someone's time!

mchlfchr
  • 3,998
  • 4
  • 26
  • 35