This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cf2410bf8a5fa898ef9dfb8e4c58c6498da72403
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Oct 18 15:21:42 2021 +0200

    CAMEL-17101: Split EIP should support splitting a java.util.Map into a 
Set<Map.Entry> - so it works out of the box, and what you would assume Camel 
can do.
---
 .../apache/camel/processor/SplitterMapTest.java    | 59 ++++++++++++++++++++++
 .../org/apache/camel/support/ObjectHelper.java     |  4 ++
 2 files changed, 63 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/SplitterMapTest.java 
b/core/camel-core/src/test/java/org/apache/camel/processor/SplitterMapTest.java
new file mode 100644
index 0000000..d6fe903
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/SplitterMapTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.processor;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+public class SplitterMapTest extends ContextTestSupport {
+
+    @Test
+    public void testSplitMap() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:line");
+        mock.message(0).body().isEqualTo("Hello World");
+        mock.message(0).header("myKey").isEqualTo("123");
+        mock.message(1).body().isEqualTo("Bye World");
+        mock.message(1).header("myKey").isEqualTo("789");
+
+        Map<String, String> map = new LinkedHashMap<>();
+        map.put("123", "Hello World");
+        map.put("789", "Bye World");
+
+        template.sendBody("direct:start", map);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .split(body())
+                        .setHeader("myKey").simple("${body.key}")
+                        .setBody(simple("${body.value}"))
+                        .to("mock:line");
+            }
+        };
+    }
+}
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java 
b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
index c4f982b..11dc820 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.concurrent.Callable;
 import java.util.regex.Pattern;
@@ -694,6 +695,9 @@ public final class ObjectHelper {
             };
         } else if (value instanceof Iterable) {
             return (Iterable<Object>) value;
+        } else if (value instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>) value;
+            return map.entrySet();
         } else if (value.getClass().isArray()) {
             if 
(org.apache.camel.util.ObjectHelper.isPrimitiveArrayType(value.getClass())) {
                 final Object array = value;

Reply via email to