Repository: camel
Updated Branches:
  refs/heads/master 3c3364d21 -> 00361c4ee


CAMEL-5604: camel-jackson added option to use list for unmarshal to pojo/map if 
the json is a list.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/00361c4e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/00361c4e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/00361c4e

Branch: refs/heads/master
Commit: 00361c4ee70d130eed1232c4ef54cf45684ab444
Parents: 3c3364d
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Jul 23 11:37:59 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Jul 23 11:37:59 2014 +0200

----------------------------------------------------------------------
 .../camel/model/dataformat/JsonDataFormat.java  | 35 +++++++++
 .../component/jackson/JackconConstants.java     | 25 ------
 .../component/jackson/JacksonConstants.java     | 25 ++++++
 .../component/jackson/JacksonDataFormat.java    | 53 +++++++++++--
 .../jackson/ListJacksonDataFormat.java          | 50 ++++++++++++
 .../JacksonMarshalUnmarshalListTest.java        | 83 ++++++++++++++++++++
 .../JacksonMarshalUnmarshalTypeHeaderTest.java  |  2 +-
 .../jackson/ListJacksonUnmarshalDTest.java      | 34 ++++++++
 .../SpringJacksonMarshalUnmarshalListTest.java  | 79 +++++++++++++++++++
 .../SpringJacksonMarshalUnmarshalListTest.xml   | 43 ++++++++++
 10 files changed, 398 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
 
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
index 73ef918..5869d12 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
@@ -50,6 +50,12 @@ public class JsonDataFormat extends DataFormatDefinition {
     private String include;
     @XmlAttribute
     private Boolean allowJmsType;
+    @XmlAttribute
+    private String collectionTypeName;
+    @XmlTransient
+    private Class<?> collectionType;
+    @XmlAttribute
+    private Boolean useList;
 
     public JsonDataFormat() {
     }
@@ -114,6 +120,22 @@ public class JsonDataFormat extends DataFormatDefinition {
         this.allowJmsType = allowJmsType;
     }
 
+    public String getCollectionTypeName() {
+        return collectionTypeName;
+    }
+
+    public void setCollectionTypeName(String collectionTypeName) {
+        this.collectionTypeName = collectionTypeName;
+    }
+
+    public Boolean getUseList() {
+        return useList;
+    }
+
+    public void setUseList(Boolean useList) {
+        this.useList = useList;
+    }
+
     @Override
     protected DataFormat createDataFormat(RouteContext routeContext) {
         if (library == JsonLibrary.XStream) {
@@ -131,6 +153,13 @@ public class JsonDataFormat extends DataFormatDefinition {
                 throw ObjectHelper.wrapRuntimeCamelException(e);
             }
         }
+        if (collectionType == null && collectionTypeName != null) {
+            try {
+                collectionType = 
routeContext.getCamelContext().getClassResolver().resolveMandatoryClass(collectionTypeName);
+            } catch (ClassNotFoundException e) {
+                throw ObjectHelper.wrapRuntimeCamelException(e);
+            }
+        }
 
         return super.createDataFormat(routeContext);
     }
@@ -152,6 +181,12 @@ public class JsonDataFormat extends DataFormatDefinition {
         if (allowJmsType != null) {
             setProperty(camelContext, dataFormat, "allowJmsType", 
allowJmsType);
         }
+        if (collectionType != null) {
+            setProperty(camelContext, dataFormat, "collectionType", 
collectionType);
+        }
+        if (useList != null) {
+            setProperty(camelContext, dataFormat, "useList", useList);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JackconConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JackconConstants.java
 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JackconConstants.java
deleted file mode 100644
index 2e4890b..0000000
--- 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JackconConstants.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.jackson;
-
-public final class JackconConstants {
-
-    public static final String UNMARSHAL_TYPE = "CamelJacksonUnmarshalType";
-
-    private JackconConstants() {
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonConstants.java
 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonConstants.java
new file mode 100644
index 0000000..fd1ffaa
--- /dev/null
+++ 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonConstants.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson;
+
+public final class JacksonConstants {
+
+    public static final String UNMARSHAL_TYPE = "CamelJacksonUnmarshalType";
+
+    private JacksonConstants() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
index 75a1d94..7f8429d 100644
--- 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
+++ 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java
@@ -18,11 +18,14 @@ package org.apache.camel.component.jackson;
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.CollectionType;
 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
@@ -35,10 +38,12 @@ import org.apache.camel.support.ServiceSupport;
 public class JacksonDataFormat extends ServiceSupport implements DataFormat {
 
     private final ObjectMapper objectMapper;
+    private Class<? extends Collection> collectionType;
     private Class<?> unmarshalType;
     private Class<?> jsonView;
     private String include;
     private boolean allowJmsType;
+    private boolean useList;
 
     /**
      * Use the default Jackson {@link ObjectMapper} and {@link Map}
@@ -62,7 +67,7 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
      * unmarshal type and JSON view
      *
      * @param unmarshalType the custom unmarshal type
-     * @param jsonView marker class to specifiy properties to be included 
during marshalling.
+     * @param jsonView marker class to specify properties to be included 
during marshalling.
      *                 See also http://wiki.fasterxml.com/JacksonJsonViews
      */
     public JacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView) {
@@ -90,7 +95,7 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
      *
      * @param mapper        the custom mapper
      * @param unmarshalType the custom unmarshal type
-     * @param jsonView marker class to specifiy properties to be included 
during marshalling.
+     * @param jsonView marker class to specify properties to be included 
during marshalling.
      *                 See also http://wiki.fasterxml.com/JacksonJsonViews
      */
     public JacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType, 
Class<?> jsonView) {
@@ -107,15 +112,19 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
 
         // is there a header with the unmarshal type?
         Class<?> clazz = unmarshalType;
-        String type = 
exchange.getIn().getHeader(JackconConstants.UNMARSHAL_TYPE, String.class);
+        String type = 
exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class);
         if (type == null && isAllowJmsType()) {
             type = exchange.getIn().getHeader("JMSType", String.class);
         }
         if (type != null) {
             clazz = 
exchange.getContext().getClassResolver().resolveMandatoryClass(type);
         }
-
-        return this.objectMapper.readValue(stream, clazz);
+        if (collectionType != null) {
+            CollectionType collType = 
objectMapper.getTypeFactory().constructCollectionType(collectionType, clazz);
+            return this.objectMapper.readValue(stream, collType);
+        } else {
+            return this.objectMapper.readValue(stream, clazz);
+        }
     }
 
     // Properties
@@ -129,6 +138,14 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
         this.unmarshalType = unmarshalType;
     }
 
+    public Class<? extends Collection> getCollectionType() {
+        return collectionType;
+    }
+
+    public void setCollectionType(Class<? extends Collection> collectionType) {
+        this.collectionType = collectionType;
+    }
+
     public Class<?> getJsonView() {
         return jsonView;
     }
@@ -153,6 +170,29 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
         return allowJmsType;
     }
 
+    public boolean isUseList() {
+        return useList;
+    }
+
+    public void setUseList(boolean useList) {
+        this.useList = useList;
+    }
+
+    /**
+     * Uses {@link java.util.ArrayList} when unmarshalling.
+     */
+    public void useList() {
+        setCollectionType(ArrayList.class);
+    }
+
+    /**
+     * Uses {@link java.util.HashMap} when unmarshalling.
+     */
+    public void useMap() {
+        setCollectionType(null);
+        setUnmarshalType(HashMap.class);
+    }
+
     /**
      * Allows jackson to use the <tt>JMSType</tt> header as an indicator what 
the classname is for unmarshaling json content to POJO
      * <p/>
@@ -164,6 +204,9 @@ public class JacksonDataFormat extends ServiceSupport 
implements DataFormat {
 
     @Override
     protected void doStart() throws Exception {
+        if (useList) {
+            setCollectionType(ArrayList.class);
+        }
         if (include != null) {
             JsonInclude.Include inc = JsonInclude.Include.valueOf(include);
             objectMapper.setSerializationInclusion(inc);

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java
 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java
new file mode 100644
index 0000000..cfe78a0
--- /dev/null
+++ 
b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/ListJacksonDataFormat.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * A {@link org.apache.camel.component.jackson.JacksonDataFormat} that is 
using a list
+ */
+public class ListJacksonDataFormat extends JacksonDataFormat {
+
+    public ListJacksonDataFormat() {
+        useList();
+    }
+
+    public ListJacksonDataFormat(Class<?> unmarshalType) {
+        super(unmarshalType);
+        useList();
+    }
+
+    public ListJacksonDataFormat(Class<?> unmarshalType, Class<?> jsonView) {
+        super(unmarshalType, jsonView);
+        useList();
+    }
+
+    public ListJacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType) {
+        super(mapper, unmarshalType);
+        useList();
+    }
+
+    public ListJacksonDataFormat(ObjectMapper mapper, Class<?> unmarshalType, 
Class<?> jsonView) {
+        super(mapper, unmarshalType, jsonView);
+        useList();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java
 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java
new file mode 100644
index 0000000..c63454a
--- /dev/null
+++ 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalListTest.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class JacksonMarshalUnmarshalListTest extends CamelTestSupport {
+
+    @Test
+    public void testUnmarshalListPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(List.class);
+
+        String json = "[{\"name\":\"Camel\"}, {\"name\":\"World\"}]";
+        template.sendBody("direct:backPojo", json);
+
+        assertMockEndpointsSatisfied();
+
+        List list = 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(list);
+        assertEquals(2, list.size());
+
+        TestPojo pojo = (TestPojo) list.get(0);
+        assertEquals("Camel", pojo.getName());
+        pojo = (TestPojo) list.get(1);
+        assertEquals("World", pojo.getName());
+    }
+
+    @Test
+    public void testUnmarshalListPojoOneElement() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(List.class);
+
+        String json = "[{\"name\":\"Camel\"}]";
+        template.sendBody("direct:backPojo", json);
+
+        assertMockEndpointsSatisfied();
+
+        List list = 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(list);
+        assertEquals(1, list.size());
+
+        TestPojo pojo = (TestPojo) list.get(0);
+        assertEquals("Camel", pojo.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                JacksonDataFormat format = new 
JacksonDataFormat(TestPojo.class);
+                format.useList();
+
+                
from("direct:backPojo").unmarshal(format).to("mock:reversePojo");
+
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
index 3c6f1db..badc856 100644
--- 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
+++ 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalUnmarshalTypeHeaderTest.java
@@ -30,7 +30,7 @@ public class JacksonMarshalUnmarshalTypeHeaderTest extends 
CamelTestSupport {
         mock.message(0).body().isInstanceOf(TestPojo.class);
 
         String json = "{\"name\":\"Camel\"}";
-        template.sendBodyAndHeader("direct:backPojo", json, 
JackconConstants.UNMARSHAL_TYPE, TestPojo.class.getName());
+        template.sendBodyAndHeader("direct:backPojo", json, 
JacksonConstants.UNMARSHAL_TYPE, TestPojo.class.getName());
 
         assertMockEndpointsSatisfied();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/ListJacksonUnmarshalDTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/ListJacksonUnmarshalDTest.java
 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/ListJacksonUnmarshalDTest.java
new file mode 100644
index 0000000..ff0abf8
--- /dev/null
+++ 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/ListJacksonUnmarshalDTest.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class ListJacksonUnmarshalDTest extends JacksonMarshalUnmarshalListTest 
{
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("direct:backPojo").unmarshal(new 
ListJacksonDataFormat(TestPojo.class)).to("mock:reversePojo");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java
 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java
new file mode 100644
index 0000000..9a68b1d
--- /dev/null
+++ 
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringJacksonMarshalUnmarshalListTest extends 
CamelSpringTestSupport {
+
+    @Test
+    public void testUnmarshalListPojo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(List.class);
+
+        String json = "[{\"name\":\"Camel\"}, {\"name\":\"World\"}]";
+        template.sendBody("direct:backPojo", json);
+
+        assertMockEndpointsSatisfied();
+
+        List list = 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(list);
+        assertEquals(2, list.size());
+
+        TestPojo pojo = (TestPojo) list.get(0);
+        assertEquals("Camel", pojo.getName());
+        pojo = (TestPojo) list.get(1);
+        assertEquals("World", pojo.getName());
+    }
+
+    @Test
+    public void testUnmarshalListPojoOneElement() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:reversePojo");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(List.class);
+
+        String json = "[{\"name\":\"Camel\"}]";
+        template.sendBody("direct:backPojo", json);
+
+        assertMockEndpointsSatisfied();
+
+        List list = 
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(list);
+        assertEquals(1, list.size());
+
+        TestPojo pojo = (TestPojo) list.get(0);
+        assertEquals("Camel", pojo.getName());
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/00361c4e/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml
 
b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml
new file mode 100644
index 0000000..7bd251a
--- /dev/null
+++ 
b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonMarshalUnmarshalListTest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <!-- START SNIPPET: e1 -->
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
+
+        <!-- we define the json jackson data formats to be used -->
+        <dataFormats>
+            <!-- and this one uses our own TestPojo class as unmarshal type -->
+            <json id="pojo" library="Jackson" useList="true" 
unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
+        </dataFormats>
+
+        <route>
+            <from uri="direct:backPojo"/>
+            <unmarshal ref="pojo"/>
+            <to uri="mock:reversePojo"/>
+        </route>
+
+    </camelContext>
+    <!-- END SNIPPET: e1 -->
+
+</beans>

Reply via email to