camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/6] camel git commit: Changed the DynamicColumnMarshaller to always use the record map to define the columns. This allows the marshaller to be reused for asymmetric records.
Date Sat, 05 Dec 2015 09:02:49 GMT
Changed the DynamicColumnMarshaller to always use the record map to define the columns. This
allows the marshaller to be reused for asymmetric records.


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

Branch: refs/heads/camel-2.16.x
Commit: aab14d7966a69abdd2dd396c4f82b79e0e0c6246
Parents: 958b66b
Author: Fabricio Toresan <fabricio.toresan@senior.com.br>
Authored: Mon Nov 30 16:42:37 2015 -0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Dec 5 10:02:00 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/dataformat/csv/CsvMarshaller.java  |  8 ++------
 .../org/apache/camel/dataformat/csv/CsvMarshalTest.java | 12 ++++++++++++
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aab14d79/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
index f23f1ec..2764d5e 100644
--- a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
+++ b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
@@ -22,7 +22,6 @@ import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -130,17 +129,14 @@ abstract class CsvMarshaller {
      * This marshaller adapts the columns but always keep them in the same order
      */
     private static final class DynamicColumnsMarshaller extends CsvMarshaller {
-        private final LinkedHashSet<Object> columns = new LinkedHashSet<Object>();
-
         private DynamicColumnsMarshaller(CSVFormat format) {
             super(format);
         }
 
         @Override
         protected Iterable<?> getMapRecordValues(Map<?, ?> map) {
-            columns.addAll(map.keySet());
-            List<Object> result = new ArrayList<Object>(columns.size());
-            for (Object key : columns) {
+            List<Object> result = new ArrayList<Object>(map.size());
+            for (Object key : map.keySet()) {
                 result.add(map.get(key));
             }
             return result;

http://git-wip-us.apache.org/repos/asf/camel/blob/aab14d79/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalTest.java
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalTest.java
index f232ad5..8f44d9b 100644
--- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalTest.java
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalTest.java
@@ -98,6 +98,18 @@ public class CsvMarshalTest extends CamelTestSupport {
         assertArrayEquals(new String[]{"A,C", "1,3", "one,three"}, readOutputLines());
     }
 
+    @Test
+    public void shouldMarshalDifferentDynamicColumns() throws Exception {
+    	output.expectedMessageCount(2);
+    	
+    	template.sendBody("direct:default", TestUtils.asMap("A", "1", "B", "2"));    	
+    	template.sendBody("direct:default", TestUtils.asMap("X", "1", "Y", "2", "Z", "3"));
+    	
+    	output.assertIsSatisfied();
+    	assertArrayEquals(new String[]{"1,2"}, readOutputLines());
+    	assertArrayEquals(new String[]{"1,2,3"}, output.getExchanges().get(1).getIn().getBody(String.class).split("\r\n|\r|\n"));
+    }
+    
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {


Mime
View raw message