JsonReferenceProcessor { public JsonNode process(File file) throws JsonReferenceException, IOException { JsonContext context = new JsonContext(file); context.setFactory(someMapperFactory()); return process(context); }  boolean isCacheInMemory(); void setCacheInMemory(boolean cacheInMemory); int getMaxDepth(); void setMaxDepth(int maxDepth); boolean isStopOnCircular(); void setStopOnCircular(boolean stopOnCircular); boolean isPreserveRefs(); void setPreserveRefs(boolean preserveRefs); boolean isPreserveLocalRefs(); void setPreserveLocalRefs(boolean preserveLocalRefs); boolean isPreserveExternalRefs(); void setPreserveExternalRefs(boolean preserveExternalRefs); String getRefPrefix(); void setRefPrefix(String refPrefix); ObjectMapperFactory getMapperFactory(); void setMapperFactory(ObjectMapperFactory mapperFactory); JsonNode process(File file); JsonNode process(URL url); JsonNode process(JsonContext context, Set<JsonReference> processed); JsonNode process(JsonContext context); JsonNode process(JsonContext context, JsonNode node); JsonNode getReplacementNode(JsonNode node, JsonContext context); JsonReference getAbsoluteRef(JsonReference ref, JsonContext context); JsonContext resolveFromContextToContext(JsonReference ref, JsonContext context); JsonNode get(JsonReference ref); JsonNode read(URL url); JsonNode read(File file); JsonNode readFile(String fileString);  }
@Test public void testDetectYamlUrl() throws JsonReferenceException, IOException { URL url = resourceAsURL("a.yaml"); String expected = "{\"a\":3}"; JsonReferenceProcessor processor = new JsonReferenceProcessor(); JsonNode node = processor.process(url); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(node); assertThat(json, equalTo(expected)); }
@Test public void testReplaceTopLevelReference() throws IOException, JsonReferenceException { File file = resourceAsFile("top.json"); JsonReferenceProcessor processor = new JsonReferenceProcessor(); JsonNode node = processor.process(file); String json = new ObjectMapper().writeValueAsString(node); String expected = "{\"a\":3}"; assertThat(json, equalTo(expected)); }
@Test public void testReplaceReferencesInArray() throws IOException, JsonReferenceException { File file = resourceAsFile("array.json"); JsonReferenceProcessor processor = new JsonReferenceProcessor(); JsonNode node = processor.process(file); String json = new ObjectMapper().writeValueAsString(node); String expected = "[{\"a\":\"a\"},{\"b\":4},{\"c\":\"d\"},{\"c\":\"d\"}]"; assertThat(json, equalTo(expected)); }
@Test public void testProcessFile() throws IOException, JsonReferenceException { File file = resourceAsFile("nest.json"); String expected = "{\"a\":3,\"b\":4,\"c\":{\"q\":{\"$ref\":\"a.json#\"}},\"nest\":[{\"ok\":\"yes\",\"why\":{\"b\":4}},\"a\"]}"; JsonNode node = (new JsonReferenceProcessor()).process(file); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(node); assertThat(json, equalTo(expected)); }
@Test public void testProcessFileWithRemote() throws IOException, JsonReferenceException { File file = resourceAsFile("remote.json"); JsonNode node = (new JsonReferenceProcessor()).process(file); ObjectMapper mapper = new ObjectMapper(); File outFile = new File("out.json"); mapper.writeValue(outFile, node); long fileLength = file.length(); assertThat(outFile.length(), greaterThan(fileLength)); assertThat(outFile.length(), greaterThan(JSON_SCHEMA_LENGTH)); }
@Test public void testProcessURLRemote() throws IOException, JsonReferenceException { URL url = new URL(JSON_SCHEMA_URL); JsonNode node = (new JsonReferenceProcessor()).process(url); ObjectMapper mapper = new ObjectMapper(); File outFile = new File("out.json"); mapper.writeValue(outFile, node); assertThat(outFile.length(), greaterThan(JSON_SCHEMA_LENGTH)); }
@Test public void testProcessURL() throws IOException, JsonReferenceException { URL url = new URL("http: JsonNode node = (new JsonReferenceProcessor()).process(url); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(node); assertThat(json, equalTo("{\"q\":{\"a\":3}}")); }
@Test public void testDetectYamlFile() throws JsonReferenceException, IOException { File file = resourceAsFile("a.yaml"); String expected = "{\"a\":3}"; JsonReferenceProcessor processor = new JsonReferenceProcessor(); JsonNode node = processor.process(file); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(node); assertThat(json, equalTo(expected)); }