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

Add CsvParser.Feature.EMPTY_STRING_AS_NULL to allow coercing empty Strings into null values #7

Closed
cowtowncoder opened this issue Mar 20, 2017 · 8 comments
Labels
Milestone

Comments

@cowtowncoder
Copy link
Member

(from FasterXML/jackson-dataformat-csv#146 by @robmoore)

We're working with a set of files that contains both empty strings and NULL values. We are using .withNullValue("NULL") as well as DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT but are ending up with empty strings rather than null values for these cases.

In issue 112, @cowtowncoder suggested it might be possible to support an alternate notation in addition to the explicit null value indicated in withNullValue().

@tyler2cr
Copy link

@cowtowncoder I'm interested in contributing to this if it's still a viable enhancement

@cowtowncoder
Copy link
Member Author

@tyler2cr yes I think this would be great thing to have. Could make it into 2.10.0, too.

@tyler2cr
Copy link

Ok - is the approach to ensure that the ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is applied to Strings when MapperFeature#ALLOW_COERCION_OF_SCALARS is enabled?

FasterXML/jackson-dataformat-csv#112 (comment)

@cowtowncoder
Copy link
Member Author

Good question. Javadocs say (at least for 2.10, it was clarified at some point):

NOTE: this does NOT apply to scalar values such as booleans and numbers ...

which means Strings, too. However... since CSV only really has scalar properties, it could be special case.
Specific discrepancy here is actually this: DeserializationFeatures are designed to work above streaming layer, after parser has indicated token type. But what we do here is to change behavior of parser, to expose empty String as null token, not String token.

Given this, I think what makes more sense is to actually define a new CsvParser.Feature, enabling of which would expose empty CSV values as nulls; and then affect all Java types.

tyler2cr pushed a commit to bizrateinsights/jackson-dataformats-text that referenced this issue Oct 1, 2019
@tyler2cr
Copy link

tyler2cr commented Oct 1, 2019

@cowtowncoder I submitted a pull request that’s ready for code review.

@cowtowncoder
Copy link
Member Author

Thanks!

@cowtowncoder cowtowncoder changed the title (csv) Support coercion of empty strings to null objects Add CsvParser.Feature.EMPTY_STRING_AS_NULL to allow coercing empty Strings into null values Oct 17, 2019
@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Oct 17, 2019
@cowtowncoder cowtowncoder modified the milestones: 2.10, 2.11.0 Oct 17, 2019
cowtowncoder added a commit that referenced this issue Oct 17, 2019
@DodoMomo
Copy link

It seems you forgot to close this issue. @cowtowncoder

@cowtowncoder
Copy link
Member Author

@DodoMomo right you are, thaks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants