8 Replies Latest reply on Mar 10, 2017 1:38 PM by cfang

    No extra quotes in data

    sunitha.n

      This is my jsl  .I kept an option to remove extra quotes on data STRICT_CHECK_FOR_QUOTING=true

      <writer ref="jacksonCsvItemWriter">

        <properties>

        <property name="resource" value="#{jobProperties['deliveryFilename']}" />

        <property name="writeMode" value="overwrite" />

        <property name="columnSeparator" value="|" />

        <property name="beanType" value="java.util.Map" />

        <property name="useHeader" value="false" />

        <property name="csvGeneratorFeatures" value="ALWAYS_QUOTE_STRINGS=false, STRICT_CHECK_FOR_QUOTING=true"/>

        <property name="columns" value="

        NAP004_FACL STRING,

        NAP004_FACL_NAME STRING,

        NAP004_ITEM STRING,

        NAP004_ITEM_DESC STRING,

        NAP004_VENDOR STRING,

        NAP004_VENDOR_NAME STRING,

        NAP004_EFF_DATE STRING,

        NAP004_END_DATE STRING,

        NAP004_AMOUNT STRING,

        NAP004_PERCENT STRING,

        NAP004_PROMO_ID STRING,

        NAP004_VENDOR_DEAL_NUM STRING,

        NAP004_SOURCE STRING,

        NAP004_FILLER STRING

        "/>

        </properties>

        </writer>

       

       

      output data  which is there in  extra quotes need to be removed

        • 1. Re: No extra quotes in data
          cfang

          I think it has to do with the inch symbol as in 12.5", which  happens to be the same as your quoteChar.  Jackson csv generator thinks it's really necessary to quote the whole field, and prefixing each inch symbol with a double-quote.

           

          RFC 4180:

          7. If double-quotes are used to enclose fields, then a double-quote

            appearing inside a field must be escaped by preceding it with

            another double quote. For example:

           

            "aaa","b""bb","ccc"

           

           

          You can try a different quote char to avoid this situation (bys setting quoteChar batch property in jacksonCsvItemWriter.  But I think the generated csv output by Jackson is valid

          • 2. Re: No extra quotes in data
            sunitha.n

            I got an issue after using property quotechar getting extra quotes when there is '#' character

            <writer ref="jacksonCsvItemWriter">

              <properties>

              <property name="resource" value="#{jobProperties['deliveryFilename']}" />

              <property name="writeMode" value="overwrite" />

              <property name="columnSeparator" value="|" />

              <property name="quoteChar" value="`" />

              <property name="beanType" value="java.util.Map" />

             

            • 3. Re: No extra quotes in data
              cfang

              # is the comment character, so Jackson csv generator decides to quote the entire field value, so this value starting with # won't be interpreted as a comment.

              • 4. Re: No extra quotes in data
                sunitha.n

                Don't want extra quotes even for special characters which are there in record .What property can be used in jackson csv item writer to remove extra quotes even for special characters ?

                I have used csvgenerator option also in jacksoncsvitem writer

                 

                <writer ref="jacksonCsvItemWriter">

                  <properties>

                  <property name="resource" value="#{jobProperties['deliveryFilename']}" />

                  <property name="writeMode" value="overwrite" />

                  <property name="columnSeparator" value="|" />

                  <property name="quoteChar" value="`" />

                  <property name="beanType" value="java.util.Map" />

                  <property name="useHeader" value="false" />

                  <property name="csvGeneratorFeatures" value="STRICT_CHECK_FOR_QUOTING=true,ALWAYS_QUOTE_STRINGS=false"/>

                • 5. Re: No extra quotes in data
                  cfang

                  can quoteChar be disabled? · Issue #32 · FasterXML/jackson-dataformat-csv · GitHub

                   

                  See the above Jackson CSV issue.

                   

                  You can try setting this batch property:

                   

                  <property name="quoteChar" value="\0"/>

                   

                   

                  to effectively disable quoting.

                   

                  I'll fix JBeret JacksonCsvItemWriter to better support disabling quoting.

                  • 6. Re: No extra quotes in data
                    cfang
                    1. JBERET-319

                    Add option to disable quoteChar in JacksonCsvItemWriter

                    • 7. Re: No extra quotes in data
                      sunitha.n

                      I used <property name="quoteChar" value="\0"/>  but its not working out.

                      • 8. Re: No extra quotes in data
                        cfang

                        You're right.  "\0" is java way of representing empty char, so it won't work in xml.  I'll test a better fix.