use of org.apache.jena.atlas.json.JsonString in project jena by apache.
the class TestJsonWriter method test.
private static void test(String str, String expected) {
JsonValue v = new JsonString(str);
str = v.toString();
assertEquals(expected, str);
}
use of org.apache.jena.atlas.json.JsonString in project jena by apache.
the class TestJsonLDWriter method testSubstitutingContext.
/**
* Test using a context to compute the output, and replacing the @context with a given value
*/
@Test
public void testSubstitutingContext() {
Model m = ModelFactory.createDefaultModel();
String ns = "http://schema.org/";
Resource person = m.createResource(ns + "Person");
Resource s = m.createResource();
m.add(s, m.createProperty(ns + "name"), "Jane Doe");
m.add(s, m.createProperty(ns + "url"), "http://www.janedoe.com");
m.add(s, m.createProperty(ns + "jobTitle"), "Professor");
m.add(s, RDF.type, person);
// change @context to a URI
JsonLDWriteContext jenaCtx = new JsonLDWriteContext();
jenaCtx.setJsonLDContextSubstitution((new JsonString(ns)).toString());
String jsonld;
jsonld = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx);
String c = "\"@context\":\"http://schema.org/\"";
assertTrue(jsonld.contains(c));
// change @context to a given ctx
String ctx = "{\"jobTitle\":{\"@id\":\"http://ex.com/jobTitle\"},\"url\":{\"@id\":\"http://ex.com/url\"},\"name\":{\"@id\":\"http://ex.com/name\"}}";
jenaCtx.setJsonLDContextSubstitution(ctx);
jsonld = toString(m, RDFFormat.JSONLD_COMPACT_FLAT, jenaCtx);
assertTrue(jsonld.contains("http://ex.com/name"));
}
Aggregations