[
https://issues.apache.org/jira/browse/CAMEL-12269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16365976#comment-16365976
]
ASF GitHub Bot commented on CAMEL-12269:
----------------------------------------
oscerd commented on issue #2225: CAMEL-12269: Bindy - Support regex expression
as separator
URL: https://github.com/apache/camel/pull/2225#issuecomment-365999786
Looks good to me. I'll merce tomorrow. Maybe @davsclaus will take a look too
----------------------------------------------------------------
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
> Priority: Major
>
> 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)