You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Andrea Cosentino (JIRA)" <ji...@apache.org> on 2018/02/16 06:58:00 UTC

[jira] [Assigned] (CAMEL-12269) Bindy - Support regex expression as separator

     [ https://issues.apache.org/jira/browse/CAMEL-12269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrea Cosentino reassigned CAMEL-12269:
----------------------------------------

    Assignee: Dmitry Volodin

> 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)