diff --git a/src/main/Main.java b/src/main/Main.java index 9cbaa7a..8b5b187 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -15,16 +15,19 @@ static RemoveJsonParam remove = new RemoveJsonParam(); static TestCactus get = new TestGETCactus(); static TestCactus post = new TestCreatePOSTCactus("f", "f", "f"); - static TestCactus logout = new TestLogoutPOSTCactus("h41ZoL44toLq3Kg7B1aXreHjcjluAsoyz8DezqiXJ28s1atiGR5UHFOqi7Or3xOD"); + static TestCactus logout = new TestLogoutPOSTCactus( + "h41ZoL44toLq3Kg7B1aXreHjcjluAsoyz8DezqiXJ28s1atiGR5UHFOqi7Or3xOD"); static TestCactus put = new TestPUTCactus("f", "f"); static TestCactus delete = new TestDELETECactus("qF9bgKYZmw8P"); public static void main(String[] args) { // logout.start(); init(); -// api.jsonAcquisition("src/main/you.json"); -// System.out.println(api.getReadJson()); -// System.out.println(api.jsonRemove("{\"snippet\":{\"title\":\"aaa\",\"status\":\"e\"}}", remove)); + api.jsonAcquisition("src/main/you.json"); + System.out.println(api.getReadJson()); + System.out.println(api.jsonRemove( + "[{\"snippet\":{\"title\":\"aaa\",\"status\":\"e\"}},{\"snippet\":{\"title\":\"aaa\",\"status\":\"e\"}}]", + remove)); // api.doRestTest(); // System.out.println(api.getResults()); } @@ -41,8 +44,8 @@ api.getGetnesParam().setQueryParams(new RestParam("access_token", "ya29.GltwBvF7RosPhYHUlEnGaorRpqpdyD1nwRAm4m3rNihRsIZV5ZgZsL3PB_3jwMJTKF1huWkKkorUPiCsunGfMySzxfutzX4y0RN9f4iw8GxFyPHBEkPZHbxsgSXF")); api.getGetnesParam().setPathParams("playlists"); -// api.setProperty("Content-type", "application/json"); - api.setRemoveParam(new RemoveJsonParam("etag",new ArrayList<>())); + // api.setProperty("Content-type", "application/json"); + api.setRemoveParam(new RemoveJsonParam("etag", new ArrayList<>())); api.setupRestTest(Method.GET, queryParam, formParam, pathParam); remove.setRemoveParam("title"); remove.setNode("snippet"); diff --git a/src/restfulchecker/RestChecker.java b/src/restfulchecker/RestChecker.java index 426c203..a29385d 100644 --- a/src/restfulchecker/RestChecker.java +++ b/src/restfulchecker/RestChecker.java @@ -236,12 +236,13 @@ public String jsonRemove(String JsonString, RemoveJsonParam param) { try { JsonNode json = new ObjectMapper().readTree(JsonString); - JsonNode current = json; - for (String node : param.getNode()) { - current = json.get(node); + if (json.getClass() != ArrayNode.class) { + jsonRemove(json, param); + } else { + for (JsonNode js : json) { + removeParam(js, param); + } } - ObjectNode obj = (ObjectNode) current; - obj.remove(param.getRemoveParam()); return json.toString(); } catch (IOException e) { // TODO Auto-generated catch block @@ -260,6 +261,15 @@ return Json.toString(); } + private void removeParam(JsonNode json, RemoveJsonParam param) { + JsonNode current = json; + for (String node : param.getNode()) { + current = json.get(node); + } + ObjectNode obj = (ObjectNode) current; + obj.remove(param.getRemoveParam()); + } + public enum Method { GET, POST, PUT, DELETE };