[
https://issues.apache.org/jira/browse/CAMEL-19143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17700393#comment-17700393
]
Brice Frisco commented on CAMEL-19143:
--------------------------------------
Expanding on this, according to RFC 4180 2.6:
{noformat}
https://www.ietf.org/rfc/rfc4180.txt
6. Fields containing line breaks (CRLF), double quotes, and commas
should be enclosed in double-quotes. For example:
"aaa","b CRLF
bb","ccc" CRLF
zzz,yyy,xxx{noformat}
So, this option would enable quoting a field *if and only if* that field:
* contains the configured `crlf` character OR
* contains the configured `quote` character OR
* contains the configured `separator` character
> Bindy - Add option to quote field only when necessary
> -----------------------------------------------------
>
> Key: CAMEL-19143
> URL: https://issues.apache.org/jira/browse/CAMEL-19143
> Project: Camel
> Issue Type: New Feature
> Components: camel-bindy
> Affects Versions: 3.20.1
> Reporter: Brice Frisco
> Priority: Minor
> Attachments: image-2023-03-13-15-14-28-952.png
>
>
> Given a POJO such as:
> {code:java}
> @CsvRecord(generateHeaderColumns = true, separator = ",")
> public class SomeOutput {
> @DataField(columnName = "hello", pos = 1)
> private String hello = "Hello,";
> @DataField(columnName = "world", pos = 2)
> private String world = "World!";
> // getters and setters
> }{code}
> And a route such as:
> {code:java}
> from("timer://test?repeatCount=1")
> .setBody(constant(new SampleOutput()))
> .marshal(CSV_FORMAT)
> .log("${body}"); {code}
> Bindy produces this output:
> {code:java}
> hello,world
> Hello,,World! {code}
> Which looks like the following in CSV format:
> !image-2023-03-13-15-14-28-952.png!
>
> Fields which contain the chosen separator are not automatically escaped or
> quoted. One workaround to this is to add `quoting=true` to the `CsvRecord`,
> which will quote all fields.
> I think it would be nice if an option existed that would quote fields only
> when it is necessary, which can reduce the file size. This method of dynamic
> quoting is the way it is handled by default in Excel on Windows systems.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)