#63 CsvToBean fails to parse embedded newlines

open
Scott Conway
None
5
2011-04-07
2011-02-22
Jenny Brown
No

I write out a csv file using CSVWriter. One field has text like: Joe said, "Blah \n blah blah."

The newline writes out correctly with CSVWriter and reads correctly with CSVReader and Excel. But CsvToBean incorrectly truncates the text at the newline. Sample code attached that reproduces the error.

Discussion

  • Jenny Brown
    Jenny Brown
    2011-02-22

    Failing demo of writing and then reading using CsvToBean

     
    Attachments
  • Scott Conway
    Scott Conway
    2011-04-07

    The reason it is failing is because the last field is picking up the newline character.

    Thanks for sending the sample program it made it easy to pin down the issue.

    If I get a chance I will look at how we deal with this in other projects.

     
  • Scott Conway
    Scott Conway
    2011-04-07

    • assigned_to: nobody --> sconway
     
  • Scott Conway
    Scott Conway
    2011-04-14

    The reason this is failing is because in the CsvToBean is trimming the
    value before passing it into the property editor to be converted to its
    proper value.

    I believe the reason for this is that if we have a value that is a number
    we would get parse exceptions if there is a space at the end. But when I
    removed the trim and ran all the unit test then they all passed.

    When I get a chance I will try writing some JUnit test to prove out my
    hypothesis and see if there is some way we can work around it.

    :)