Hi,

yogu13 wrote
> would you have any test case which can be used to reproduce it?

I wrote a simple unit test for the given scenario. The expected outcome is
"ABC" as the first csv field in the output file. I'm using Camel 2.15.0 and
Java 8.

import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.CsvDataFormat;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class CsvTest extends CamelTestSupport {

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {

                // Create and configure the csv component
                final CsvDataFormat csv = new CsvDataFormat();
                csv.setLazyLoad(Boolean.FALSE);
                csv.setDelimiter(";");
                csv.setRecordSeparator("\r\n");
                csv.setIgnoreSurroundingSpaces(Boolean.FALSE);

                from("file://target/inbox")
                  .unmarshal(csv)
                  .marshal(csv)
                .to("file://target/outbox");
            }
        };
    }

    @Test
    public void testCsvFieldWithQuotes() throws Exception {

        // A csv row: "one";"two ";three
        final String inputRow = "\"ABC\";\"DEF \";GHI\r\n";

        // Simulate file drop
        template
            .sendBodyAndHeader("file://target/inbox", inputRow,
Exchange.FILE_NAME, "csvFile.txt");
        Thread.sleep(2000);

        // Assert that the content of the file is the expected csv row
        // Expect ABC to be surrounded by quotes
        String outputRow= new
String(Files.readAllBytes(Paths.get("target/outbox/csvFile.txt")));
        assertEquals(inputRow, outputRow);

    }
}

I would like to "force" to have quotations on the ABC field

Regards 
Hans-Christian



--
View this message in context: 
http://camel.465427.n5.nabble.com/Problem-to-write-quotes-correct-on-CSV-fields-when-marshalling-with-CsvDataFormat-tp5765477p5765663.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to