public static Registry load(InputStream r) { try{ return JacksonUtils.getReader().forType(Registry.class) .readValue(new InputStreamReader(r)); }catch (Exception e) { throw new IllegalStateException(e); } }
public Registry get() { try { String str = HTTPUtil.readString(registryUrl); Registry readValue = JacksonUtils.getReader().forType(Registry.class) .readValue(new StringReader(str)); return readValue; } catch (IOException e) { throw new IllegalStateException(e); } }
@Override public JsonNode transform(JsonNode patched) throws IOException { Iterator<Map.Entry<String, JsonNode>> nodeIterator = patched.get("message").fields(); while (nodeIterator.hasNext()) { Map.Entry<String, JsonNode> entry = nodeIterator.next(); if (!KNOWN_KEYS.contains(entry.getKey())) { String json = format(MOVE_OP, entry.getKey()); try { patched = JsonPatch.fromJson(JacksonUtils.getReader().readTree(json)).apply(patched); } catch (JsonPatchException e) { throw new RuntimeException("move operation could not be applied", e); } } } return patched; } }
/** * Static factory method to build a JSON Patch out of a JSON representation * * @param node the JSON representation of the generated JSON Patch * @return a JSON Patch * @throws IOException input is not a valid JSON patch * @throws NullPointerException input is null */ public static JsonPatch fromJson(final JsonNode node) throws IOException { BUNDLE.checkNotNull(node, "jsonPatch.nullInput"); return JacksonUtils.getReader().withType(JsonPatch.class) .readValue(node); }
@Override public Registry get() { try{ File fs=File.createTempFile("ddd", "tmp"); HTTPUtil.readToFile(url, fs); ZipUtil.extractFolder(fs.getAbsolutePath(), path); for (File f:new File(path).listFiles()){ if (f.getName().endsWith(".json")){ String str=FileUtils.readFileToString(f); Registry readValue = JacksonUtils.getReader().forType(Registry.class) .readValue(new StringReader(str)); readValue.items().forEach(x->{ x.setLocation(new File(path,x.getLocation()).getAbsolutePath()); }); return readValue; } } return null; }catch (Exception e) { throw new IllegalStateException(e); } }
try { String str = FileUtils.readFileToString(f); Registry readValue = JacksonUtils.getReader().forType(Registry.class) .readValue(new StringReader(str)); LocalRegistry rs=new LocalRegistry(releaseFolder.getAbsolutePath()); if (f.getName().endsWith(".json")){ String str=FileUtils.readFileToString(f); Registry readValue = JacksonUtils.getReader().forType(Registry.class) .readValue(new StringReader(str)); readValue.items().forEach(x->{
protected JsonPatchOperationTest(final String prefix) throws IOException { final String resource = "/jsonpatch/" + prefix + ".json"; final JsonNode node = JsonLoader.fromResource(resource); errors = node.get("errors"); ops = node.get("ops"); reader = JacksonUtils.getReader().withType(JsonPatchOperation.class); }
@Test(dataProvider = "getObjectInputs") public void objectSerDeserWorksCorrectly(final JsonNode input) throws IOException { final String in = input.toString(); final JsonMergePatch deserialized = mapper.readValue(in, JsonMergePatch.class); assertNotNull(deserialized); assertSame(deserialized.getClass(), ObjectMergePatch.class); final String out = mapper.writeValueAsString(deserialized); final JsonNode serialized = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, serialized)); } }
@Test(dataProvider = "getNonObjectInputs") public void nonObjectSerDeserWorksCorrectly(final JsonNode input) throws IOException { final String in = input.toString(); final JsonMergePatch deserialized = mapper.readValue(in, JsonMergePatch.class); assertNotNull(deserialized); assertSame(deserialized.getClass(), NonObjectMergePatch.class); final String out = mapper.writeValueAsString(deserialized); final JsonNode serialized = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, serialized)); }
final JsonNode output = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, output));