[
https://issues.apache.org/jira/browse/CAMEL-12269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16366662#comment-16366662
]
ASF GitHub Bot commented on CAMEL-12269:
----------------------------------------
oscerd closed pull request #2225: CAMEL-12269: Bindy - Support regex expression
as separator
URL: https://github.com/apache/camel/pull/2225
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/components/camel-bindy/pom.xml b/components/camel-bindy/pom.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFactory.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/Format.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/Format.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/FormatFactory.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/PatternFormat.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/PatternFormat.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/DataField.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Link.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/Link.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/LinkType.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/LinkType.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
old mode 100755
new mode 100644
index 00ea80900bd..9b5b1c43ea7
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.Map;
import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.camel.Exchange;
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
@@ -152,7 +154,7 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
// Retrieve the separator defined to split the record
String separator = factory.getSeparator();
- String quote = factory .getQuote();
+ String quote = factory.getQuote();
ObjectHelper.notNull(separator, "The separator has not been
defined in the annotation @CsvRecord or not instantiated during initModel.");
int count = 0;
@@ -184,10 +186,23 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
// Split the CSV record according to the separator defined in
// annotated class @CSVRecord
- String[] tokens = line.split(separator,
factory.getAutospanLine() ? factory.getMaxpos() : -1);
+ Pattern pattern = Pattern.compile(separator);
+ Matcher matcher = pattern.matcher(line);
+ List<String> separators = new ArrayList<String>();
+
+ // Retrieve separators for each match
+ while (matcher.find()) {
+ separators.add(matcher.group());
+ }
+ // Add terminal separator
+ if (separators.size() > 0) {
+ separators.add(separators.get(separators.size() - 1));
+ }
+
+ String[] tokens = pattern.split(line,
factory.getAutospanLine() ? factory.getMaxpos() : -1);
List<String> result = Arrays.asList(tokens);
// must unquote tokens before use
- result = unquoteTokens(result, separator, quote);
+ result = unquoteTokens(result, separators, quote);
if (result.size() == 0 || result.isEmpty()) {
throw new java.lang.IllegalArgumentException("No records
have been defined in the CSV");
@@ -233,7 +248,7 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
* as will handling fixing broken tokens which may have been split
* by a separator inside a quote.
*/
- private List<String> unquoteTokens(List<String> result, String separator,
String quote) {
+ private List<String> unquoteTokens(List<String> result, List<String>
separators, String quote) {
// a current quoted token which we assemble from the broken pieces
// we need to do this as we use the split method on the String class
// to split the line using regular expression, and it does not handle
@@ -242,6 +257,7 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
StringBuilder current = new StringBuilder();
boolean inProgress = false;
List<String> answer = new ArrayList<String>();
+ int idxSeparator = 0;
//parsing assumes matching close and end quotes
for (String s : result) {
@@ -279,7 +295,7 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
// are we in progress of rebuilding a broken token
if (inProgress) {
- current.append(separator);
+ current.append(separators.get(idxSeparator));
current.append(s);
if (canClose) {
@@ -296,7 +312,7 @@ public Object unmarshal(Exchange exchange, InputStream
inputStream) throws Excep
answer.add(s);
}
}
-
+ idxSeparator++;
}
// any left over from current?
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/NumberPatternFormat.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/BooleanFormatFactory.java
old mode 100755
new mode 100644
diff --git a/components/camel-bindy/src/main/resources/META-INF/LICENSE.txt
b/components/camel-bindy/src/main/resources/META-INF/LICENSE.txt
old mode 100755
new mode 100644
diff --git a/components/camel-bindy/src/test/data/big/csv.txt
b/components/camel-bindy/src/test/data/big/csv.txt
old mode 100755
new mode 100644
diff --git a/components/camel-bindy/src/test/data/csv.txt
b/components/camel-bindy/src/test/data/csv.txt
old mode 100755
new mode 100644
diff --git a/components/camel-bindy/src/test/data2/csv.txt
b/components/camel-bindy/src/test/data2/csv.txt
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvUnmarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexRegexSeparatorTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexRegexSeparatorTest.java
new file mode 100644
index 00000000000..666d5f92e07
--- /dev/null
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexRegexSeparatorTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.dataformat.bindy.csv;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class BindyComplexRegexSeparatorTest extends CamelTestSupport {
+ @CsvRecord(separator = "[,;]", skipFirstLine = true)
+ public static class Example {
+ @DataField(pos = 1)
+ private String field1;
+
+ @DataField(pos = 2)
+ private String field2;
+ }
+
+ @Test
+ public void testUnmarshal() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:unmarshal",
"header1,header2\n\"value1\",\"value,2\"");
+
+ assertMockEndpointsSatisfied();
+ Example body =
mock.getReceivedExchanges().get(0).getIn().getBody(Example.class);
+ assertEquals("value,2", body.field2);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:unmarshal").unmarshal().bindy(BindyType.Csv,
Example.class).to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCsvBigFileUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCsvBigFileUnmarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyPojoSimpleCsvMarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyPojoSimpleCsvMarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvBooleanUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvBooleanUnmarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvIntegerMarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvIntegerMarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallDslTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallDslTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvSkipFirstLineUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvSkipFirstLineUnmarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Client.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Client.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Order.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/twoclassesandonelink/Order.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclass/Order.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclass/Order.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandskipfirstline/Order.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassandskipfirstline/Order.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassemptystream/Order.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassemptystream/Order.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmandatory/Order.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassmandatory/Order.java
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvGenerateHeaderMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyCsvBigFileUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyCsvBigFileUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyCsvUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyCsvUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyPojoSimpleCsvMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyPojoSimpleCsvMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvGenerateHeaderMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvIntegerMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvIntegerMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallDslTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallDslTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvNullMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvNullMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvSkipFirstLineUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvSkipFirstLineUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallPositionModifiedTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallPositionModifiedTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairFixTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairFixTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairNullMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairNullMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabMarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabMarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabUnmarshallTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallDslTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallDslTest-context.xml
old mode 100755
new mode 100644
diff --git
a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallTest-context.xml
b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallTest-context.xml
old mode 100755
new mode 100644
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Bindy - Support regex expression as separator
> ---------------------------------------------
>
> Key: CAMEL-12269
> URL: https://issues.apache.org/jira/browse/CAMEL-12269
> Project: Camel
> Issue Type: New Feature
> Components: camel-bindy
> Affects Versions: 2.20.2
> Reporter: Bohdan
> Assignee: Dmitry Volodin
> Priority: Major
> Fix For: 2.21.0
>
>
> I try to unmarshal CSV file into the class below:
> {code:java}
> @CsvRecord(separator = "[,;]", skipFirstLine = true)
> public class Example {
> @DataField(pos = 1)
> private String field1;
> @DataField(pos = 2)
> private String field2;
> }{code}
> CSV file:
> {code:java}
> header1,header2
> "value_1","value,2"
> {code}
> After unmarshalling I get the following value for field2: "value[,;]2".
> However, the correct value for field2 should be "value,2".
> Complete test:
> {code:java}
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
> import org.apache.camel.dataformat.bindy.annotation.DataField;
> import org.apache.camel.model.dataformat.BindyType;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
> public class BindyTest extends CamelTestSupport {
> @CsvRecord(separator = "[,;]", skipFirstLine = true)
> public static class Example {
> @DataField(pos = 1)
> private String field1;
> @DataField(pos = 2)
> private String field2;
> }
> @Test
> public void testUnmarshal() throws Exception {
> MockEndpoint mock = getMockEndpoint("mock:result");
> mock.expectedMessageCount(1);
> template.sendBody("direct:unmarshal",
> "header1,header2\n\"value1\",\"value,2\"");
> assertMockEndpointsSatisfied();
> Example body =
> mock.getReceivedExchanges().get(0).getIn().getBody(Example.class);
> assertEquals("value,2", body.field2);
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> from("direct:unmarshal")
> .unmarshal().bindy(BindyType.Csv, Example.class)
> .to("mock:result");
> }
> };
> }
> }
> {code}
> *Possible workaround:*
> Use separator {code}"[,;](?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)"{code}
> (regex explained in https://stackoverflow.com/a/18893443)
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)