Repository: camel Updated Branches: refs/heads/master 8b03c37a9 -> 41884a241
CAMEL-9605 update default unmarshall type to java.lang.Object instead of java.util.Map to be able to unmarshall any valid Json document with the default configuration of Gson umarshaller Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ee9c5a35 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ee9c5a35 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ee9c5a35 Branch: refs/heads/master Commit: ee9c5a357ee458e86eb80b53901c1453658114eb Parents: 8b03c37 Author: Xavier Fournet <xavier.four...@gmail.com> Authored: Mon Feb 15 19:02:36 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Feb 15 19:29:44 2016 +0100 ---------------------------------------------------------------------- .../camel/component/gson/GsonDataFormat.java | 2 +- .../component/gson/GsonDataFormatTest.java | 35 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ee9c5a35/components/camel-gson/src/main/java/org/apache/camel/component/gson/GsonDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-gson/src/main/java/org/apache/camel/component/gson/GsonDataFormat.java b/components/camel-gson/src/main/java/org/apache/camel/component/gson/GsonDataFormat.java index 8a49dd8..79ccb5e 100644 --- a/components/camel-gson/src/main/java/org/apache/camel/component/gson/GsonDataFormat.java +++ b/components/camel-gson/src/main/java/org/apache/camel/component/gson/GsonDataFormat.java @@ -57,7 +57,7 @@ public class GsonDataFormat extends ServiceSupport implements DataFormat, DataFo private String dateFormatPattern; public GsonDataFormat() { - this(Map.class); + this(Object.class); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/ee9c5a35/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java new file mode 100644 index 0000000..2e014ce --- /dev/null +++ b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonDataFormatTest.java @@ -0,0 +1,35 @@ +package org.apache.camel.component.gson; + +import java.io.*; +import java.util.*; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class GsonDataFormatTest { + @Test + public void testString() throws Exception { + testJson("\"A string\"", "A string"); + } + + @Test + public void testMap() throws Exception { + testJson("{value=123}", Collections.singletonMap("value", 123.0)); + } + + @Test + public void testList() throws Exception { + testJson("[{value=123}]", Collections.singletonList(Collections.singletonMap("value", 123.0))); + } + + private void testJson(String json, Object expected) throws Exception { + Object unmarshalled; + GsonDataFormat gsonDataFormat = new GsonDataFormat(); + gsonDataFormat.doStart(); + try (InputStream in = new ByteArrayInputStream(json.getBytes())) { + unmarshalled = gsonDataFormat.unmarshal(null, in); + } + + assertEquals(expected, unmarshalled); + } +}