[
https://issues.apache.org/jira/browse/CAMEL-12269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bohdan updated CAMEL-12269:
---------------------------
Description:
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}
was:
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".
> Bindy - Incorrect handling of values enclosed in quotes with regex separator
> ----------------------------------------------------------------------------
>
> Key: CAMEL-12269
> URL: https://issues.apache.org/jira/browse/CAMEL-12269
> Project: Camel
> Issue Type: Bug
> 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}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)