Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CSV to differentiate between null and empty fields (foo,,bar vs. foo,"",bar) #469

Closed
PujolDavid opened this issue Mar 29, 2024 · 3 comments
Labels
2.18 Fix or feature targeted at 2.18 release pr-needed Feature request for which PR likely needed (no active development but idea is workable)
Milestone

Comments

@PujolDavid
Copy link
Contributor

I have not found any way to read a CSV that differentiate null and empty values.
I have played with various options and I also do a debug step by step in the jackson code.

The need is to be able to read a CSV generated by Postgres (and other apps) that make a difference between null and empty values.

Here an example of a 2 lines CSV:
foo,,bar
foo,"",bar

I expect to retrieve the following arrays:
["foo", null, "bar"]
["foo", "", "bar]

Can we add an option in CsvParser.Feature such as EMPTY_NON_QUOTED_STRING_AS_NULL?
This will also help to read CSV created with CsvGenerator.Feature.ALWAYS_QUOTE_EMPTY_STRINGS option

Thanks for taking time to read me.

@cowtowncoder cowtowncoder added the pr-needed Feature request for which PR likely needed (no active development but idea is workable) label Apr 1, 2024
@cowtowncoder
Copy link
Member

While we are always open for improvements and suggestions, I am not quite sure about this one -- conceptually it seems to me that both cases should be the same. That is, quoting (or not) should not have effect on resulting value.

Having said that, if someone can implement the difference cleanly as PR (and enabled via CsvParser.Feature), I would accept the contribution.

@PujolDavid
Copy link
Contributor Author

I made the following PR #471

Note that this PR is done on version 2.18, but I will be happy to do the PR for previous version if accepted (I'm using 2.14/2.15 with Spring boot 3.0/3.1)

@cowtowncoder cowtowncoder added the 2.18 Fix or feature targeted at 2.18 release label Apr 10, 2024
@cowtowncoder cowtowncoder changed the title CSV - differentiating between null and empty fields (foo,,bar vs. foo,"",bar) Allow CSV to differentiate between null and empty fields (foo,,bar vs. foo,"",bar) Apr 10, 2024
cowtowncoder added a commit that referenced this issue Apr 10, 2024
@cowtowncoder cowtowncoder added this to the 2.18.0 milestone Apr 10, 2024
@cowtowncoder
Copy link
Member

As per my notes on PR this feature will officially be added in 2.18(.0), but technically is merged into 2.17 branch so will be "dark launch"ed in 2.17.1, as a preview feature of sort.
This because it'll be a while until 2.18.0 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Fix or feature targeted at 2.18 release pr-needed Feature request for which PR likely needed (no active development but idea is workable)
Projects
None yet
Development

No branches or pull requests

2 participants