Package org.apache.jena.riot.writer
Class JsonLDWriter
- java.lang.Object
-
- org.apache.jena.riot.writer.WriterDatasetRIOTBase
-
- org.apache.jena.riot.writer.JsonLDWriter
-
- All Implemented Interfaces:
WriterDatasetRIOT
public class JsonLDWriter extends WriterDatasetRIOTBase
Writer that prints out JSON-LD. By default, the output is "compact" (in JSON-LD terminology), and the JSON is "pretty" (using line breaks). One can choose another form using one of the dedicated RDFFormats (JSONLD_EXPAND_PRETTY, etc.). For formats using a context (that is, which have an "@context" node), (compact and expand), this automatically generates a default one. One can pass a jsonld context using the (jena) Context mechanism, defining a (jena) Context (sorry for this clash of "contexts"), (cf. last argument inWriterDatasetRIOT.write(OutputStream out, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context)
) with:Context jenaContext = new Context() jenaCtx.set(JsonLDWriter.JSONLD_CONTEXT, contextAsJsonString);
where contextAsJsonString is a JSON string containing the value of the "@context". It is possible to change the content of the "@context" node in the output using theJSONLD_CONTEXT_SUBSTITUTION
Symbol. For a frame output, one must pass a frame in the jenaContext using theJSONLD_FRAME
Symbol. It is also possible to define the different options supported by JSONLD-java using theJSONLD_OPTIONS
Symbol TheJsonLDWriteContext
is a convenience class that extends Context and provides methods to set the values of these different Symbols that are used in controlling the writing of JSON-LD. Note that this class also provides a static method to convert jena RDF data to the corresponding object in JsonLD API:toJsonLDJavaAPI(org.apache.jena.riot.RDFFormat.JSONLDVariant, DatasetGraph, PrefixMap, String, Context)
-
-
Field Summary
Fields Modifier and Type Field Description static Symbol
JSONLD_ADD_ALL_PREFIXES_TO_CONTEXT
if creating a (jsonld) context from dataset, should we include all the prefixes defined in graph's prefix mappings value: a Boolean (default: true)static Symbol
JSONLD_CONTEXT
Expected value: the value of the "@context" (a JSON String, or the object expected by the JSONLD-java API)static Symbol
JSONLD_CONTEXT_SUBSTITUTION
Expected value: the value of the "@context" to be put in final output (a JSON String) This is NOT the context used to produce the output (given by JSONLD_CONTEXT, or computed from the input RDF.static Symbol
JSONLD_FRAME
value: a JSON String, or the frame object expected by JsonLdProcessor.framestatic Symbol
JSONLD_OPTIONS
value: the option object expected by JsonLdProcessor (instance of JsonLdOptions)
-
Constructor Summary
Constructors Constructor Description JsonLDWriter(RDFFormat syntaxForm)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Lang
getLang()
static java.lang.Object
toJsonLDJavaAPI(RDFFormat.JSONLDVariant variant, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context jenaContext)
the JsonLD-java API object corresponding to a dataset and a JsonLD format.void
write(java.io.OutputStream out, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context context)
void
write(java.io.Writer out, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context context)
Use of Writer is discouraged - let the serializer manage character sets in accordance with the format
-
-
-
Field Detail
-
JSONLD_CONTEXT
public static final Symbol JSONLD_CONTEXT
Expected value: the value of the "@context" (a JSON String, or the object expected by the JSONLD-java API)
-
JSONLD_CONTEXT_SUBSTITUTION
public static final Symbol JSONLD_CONTEXT_SUBSTITUTION
Expected value: the value of the "@context" to be put in final output (a JSON String) This is NOT the context used to produce the output (given by JSONLD_CONTEXT, or computed from the input RDF. It is something that will replace the @context content. This is useful- for the cases you want to have a URI as value of @context, without having JSON-LD java to download it and
- as a trick to change the URIs in your result.
-
JSONLD_FRAME
public static final Symbol JSONLD_FRAME
value: a JSON String, or the frame object expected by JsonLdProcessor.frame
-
JSONLD_OPTIONS
public static final Symbol JSONLD_OPTIONS
value: the option object expected by JsonLdProcessor (instance of JsonLdOptions)
-
JSONLD_ADD_ALL_PREFIXES_TO_CONTEXT
public static final Symbol JSONLD_ADD_ALL_PREFIXES_TO_CONTEXT
if creating a (jsonld) context from dataset, should we include all the prefixes defined in graph's prefix mappings value: a Boolean (default: true)
-
-
Constructor Detail
-
JsonLDWriter
public JsonLDWriter(RDFFormat syntaxForm)
-
-
Method Detail
-
getLang
public Lang getLang()
-
write
public void write(java.io.Writer out, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context context)
Description copied from interface:WriterDatasetRIOT
Use of Writer is discouraged - let the serializer manage character sets in accordance with the format- Specified by:
write
in interfaceWriterDatasetRIOT
- Specified by:
write
in classWriterDatasetRIOTBase
- Parameters:
out
- Writerdataset
- DatasetGraph to be writtenprefixMap
- PrefixMap - maybe null (default should be to use the prefix mapping from the Graph)baseURI
- base URI - may be null for "none"context
- Context (see specific implementation for details)
-
write
public void write(java.io.OutputStream out, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context context)
- Specified by:
write
in interfaceWriterDatasetRIOT
- Specified by:
write
in classWriterDatasetRIOTBase
- Parameters:
out
- OutputStreamdataset
- DatasetGraph to be writtenprefixMap
- PrefixMap - maybe null (default should be to use the prefix mapping from the Graph)baseURI
- base URI - may be null for "none"context
- Context (see specific implementation for details)
-
toJsonLDJavaAPI
public static java.lang.Object toJsonLDJavaAPI(RDFFormat.JSONLDVariant variant, DatasetGraph dataset, PrefixMap prefixMap, java.lang.String baseURI, Context jenaContext) throws com.github.jsonldjava.core.JsonLdError, com.fasterxml.jackson.core.JsonParseException, java.io.IOException
the JsonLD-java API object corresponding to a dataset and a JsonLD format.- Throws:
com.github.jsonldjava.core.JsonLdError
com.fasterxml.jackson.core.JsonParseException
java.io.IOException
-
-