/** * Returns a new (mutable) JSON-LD options instance based on this context. */ public JsonLdOptions jsonLdOptions() { // TODO Technically both the documentLoader and potentially expandContext are mutable JsonLdOptions options = new JsonLdOptions(); options.setDocumentLoader(documentLoader); options.setBase(base); options.setExpandContext(expandContext); options.setOmitDefault(Boolean.TRUE); return options; }
@Test public void injectContext() throws Exception { final Object jsonObject = JsonUtils.fromString( "{ \"@context\":\"http://nonexisting.example.com/thing\", \"pony\":5 }"); final JsonLdOptions options = new JsonLdOptions(); // Verify fails to find context by default try { JsonLdProcessor.expand(jsonObject, options); fail("Expected exception to occur"); } catch (final JsonLdError e) { // Success } // Inject context final DocumentLoader dl = new DocumentLoader(); dl.addInjectedDoc("http://nonexisting.example.com/thing", "{ \"@context\": { \"pony\":\"http://nonexisting.example.com/thing/pony\" } }"); options.setDocumentLoader(dl); // Execute final List<Object> expand = JsonLdProcessor.expand(jsonObject, options); // Verify result final Object v = ((Map<Object, Object>) ((List<Object>) ((Map<Object, Object>) expand .get(0)).get("http://nonexisting.example.com/thing/pony")).get(0)).get("@value"); assertEquals(5, v); }
final TestDocumentLoader testLoader = new TestDocumentLoader( "http://json-ld.org/test-suite/tests/"); options.setDocumentLoader(testLoader); if (test.containsKey("option")) { final Map<String, Object> test_opts = (Map<String, Object>) test.get("option");
options.setDocumentLoader(documentLoader); final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(arrayContext, options);