/** Test passing a JsonLdOptions through Context */ @Test public final void jsonldOptions() { Model m = ModelFactory.createDefaultModel(); String ns = "http://schema.org/"; 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"); // our default uses true for compactArrays String jsonld = toString(m, RDFFormat.JSONLD, null); // compactArrays is true -> no "@graph" assertFalse(jsonld.contains("@graph")); // compactArrays is true -> string, not an array for props with one value assertTrue(jsonld.contains("\"jobTitle\" : \"Professor\"")); // now output using a value for JsonLdOptions in Context that sets compactArrays to false JsonLDWriteContext jenaCtx = new JsonLDWriteContext(); JsonLdOptions opts = new JsonLdOptions(null); opts.setCompactArrays(false); jenaCtx.setOptions(opts); jsonld = toString(m, RDFFormat.JSONLD, jenaCtx); // compactArrays is false -> a "@graph" node assertTrue(jsonld.contains("@graph")); // compactArrays is false -> an array for all props, even when there's only one value assertTrue(jsonld.contains("\"jobTitle\" : [ \"Professor\" ]")); }