From 632b93761a17e4887e0b64b850405ba2b6ae477e Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Sat, 27 Jan 2018 14:07:46 +0100 Subject: [PATCH] Including null attributes #31 --- CHANGELOG.md | 17 +++++++++++++++++ .../plugins/gwt/resolvers/JsonFlattener.java | 5 ++++- .../gwt/VariablesResolverJsonPathTest.java | 14 ++++++++++++++ .../plugins/gwt/VariablesResolverXPathTest.java | 4 ++-- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da03b0a..33bfaff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Generic Webhook Plugin Changelog Changelog of Generic Webhook Plugin. +## Unreleased +### GitHub [#31](https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/31) Wanna get all request body that payload body including null value + +**Including null attributes #31** + + +[6829688da6c3d17](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/6829688da6c3d17) Tomas Bjerre *2018-01-27 13:07:46* + + +### No issue + +**Removing newlines from assert in test** + + +[92ced8a3dc25a34](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/92ced8a3dc25a34) Tomas Bjerre *2018-01-03 12:33:36* + + ## 1.22 (2018-01-03 12:22:47) ### GitHub [#30](https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/30) Request: Supporting of JSON header without flattening diff --git a/src/main/java/org/jenkinsci/plugins/gwt/resolvers/JsonFlattener.java b/src/main/java/org/jenkinsci/plugins/gwt/resolvers/JsonFlattener.java index 3934199..7fea2c2 100644 --- a/src/main/java/org/jenkinsci/plugins/gwt/resolvers/JsonFlattener.java +++ b/src/main/java/org/jenkinsci/plugins/gwt/resolvers/JsonFlattener.java @@ -12,7 +12,10 @@ import com.google.gson.GsonBuilder; public class JsonFlattener { - private static Gson GSON = new GsonBuilder().create(); + private static Gson GSON = + new GsonBuilder() // + .serializeNulls() // + .create(); public JsonFlattener() {} diff --git a/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverJsonPathTest.java b/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverJsonPathTest.java index f03eb3b..7dc0a66 100644 --- a/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverJsonPathTest.java +++ b/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverJsonPathTest.java @@ -111,6 +111,15 @@ public void testJSONPathGetSeveralMixedListItems() throws Exception { "[{\"name\":\"Administrator\"},{\"username\":\"root\"},\"a simple string\",33333,{\"a number\":\"a value\"},\"another simple string\",66666,{\"another number\":\"another value\"}]"); } + @Test + public void testJSONPathGetNullValues() throws Exception { + final Map variables = + getJsonPathVariablesFromContent("$", "{\"a\": null,\"b\": \"value\"}"); + + assertThat(variables.get("variableName")) // + .isEqualTo("{\"a\":null,\"b\":\"value\"}"); + } + @Test public void testJSONPathGetAllVariable() throws Exception { final String resourceName = "gitlab-mergerequest-comment.json"; @@ -344,6 +353,11 @@ private Map getJsonPathVariables( final String resourceName, final String jsonPath) { final String postContent = getContent(resourceName); + return getJsonPathVariablesFromContent(jsonPath, postContent); + } + + private Map getJsonPathVariablesFromContent( + final String jsonPath, final String postContent) { final String regexpFilter = ""; final List genericVariables = newArrayList( // diff --git a/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverXPathTest.java b/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverXPathTest.java index 525509e..2b94aee 100644 --- a/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverXPathTest.java +++ b/src/test/java/org/jenkinsci/plugins/gwt/VariablesResolverXPathTest.java @@ -269,7 +269,7 @@ public void testXPathTwoListListItemsFirstBook() throws Exception { assertThat(variables.get("book").replaceAll("\\r|\\n|\\s", "")) // .isEqualTo( - "1content12content2"); + "1content12content2"); } @Test @@ -298,7 +298,7 @@ public void testXPathRootElement() throws Exception { assertThat(variables.get("book").replaceAll("\\r|\\n|\\s", "")) // .isEqualTo( - "1content12content221content21"); + "1content12content221content21"); } @Test