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
CSV EMPTY_STRING_AS_NULL with non-nullable default value = exception #605
Comments
Ok, this fixes it for me:
However, I'm not really passing null here, I'm just deciding how empty cells in my CSV should be handled (absent any other value, such as a default value), so it feels a bit odd that I have to enable this KotlinFeature. |
Put differently, the usage of default parameter should be the default when parsing a CSV and encountering an empty cell, regardless of whether or not EMPTY_STRING_AS_NULL is used, in my opinion. |
@hosswald Unfortunately I am not sure it is possible to have such cross-dependencies; use of CSV backend is independent of use of Kotlin module. And from architecture perspective there is no good way to add such constraints, even if they might make sense. |
@cowtowncoder I just looked a bit through the test cases for jackson-dataformats-text/csv... |
@hosswald Yes, I think that if handling can be defined in more general way, not relying on some specific Kotlin aspect, it'd make sense to file an RFE there. |
Describe the bug
I have a csv with empty cells. I generally want those to be parsed as null. However, I want to also have the ability to parse these cells into non-nullable properties by defining a default value in the constructor. Unfortunately, this leads to an exception:
To Reproduce
Expected behavior
It can be argued that a json like
{"bar":null, "baz":"42"}
should produce an error when parsed intoFoo
, because there is an explicit null.However, in the case of CSV, there is no such thing as "explicit null". The value is only null because of
CsvParser.Feature.EMPTY_STRING_AS_NULL
. Therefore, I would expect the above test not to fail.KotlinValueInstantiator should probably handle this case by setting
isMissing = true
, which would likely fix the problem (I did not test this, I only had a brief look at the code).Versions
Kotlin: 1.7.20
Jackson-module-kotlin: 2.14.0
Jackson-databind: 2.14.0
The text was updated successfully, but these errors were encountered: