Adam,
In the first instance, this seems like something to raise with the
jsonld-java team to find out if that is intentional. Could you open a
discussion issue there?
IIRC empty prefix and the base are mixed up in JSON-LD.
Andy
On 04/01/18 03:34, Adam Jacobs wrote:
The @vocab prefix is dropped by Jena when parsing JsonLD.
An empty prefix is correctly translated into @vocab during serialization, but
is lost during deserialization.
Below code demonstrates the point.
public static void main(String... args) {
String base = "http://www.ns.com/base/";
String prefix = "http://www.ns.com/prefix/";
Model m = ModelFactory.createDefaultModel();
m.setNsPrefix("", base);
m.setNsPrefix("prefix", prefix);
m.add(m.createResource(base + "foo"), m.createProperty(prefix + "bar"),
m.createResource(base + "baz"));
String jsonLD = serializeJsonLD(m);
System.out.println(jsonLD);
InputStream in = new ByteArrayInputStream(jsonLD.getBytes());
Model m2 = ModelFactory.createDefaultModel().read(in, null, "jsonld");
System.out.println(serializeJsonLD(m2));
}
public static String serializeJsonLD(Model m) {
OutputStream out = new ByteArrayOutputStream();
m.write(out, "jsonld");
return out.toString();
}
From what I can see, jsonld-java is intentionally ignoring the @vocab key at
line 277 of Context.java.
https://github.com/jsonld-java/jsonld-java/blob/master/core/src/main/java/com/github/jsonldjava/core/Context.java
I'm not sure if this is a bug in jsonld-java, or intentional behavior from a
jsonld perspective that Jena should work around e.g. in JsonLDReader?