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

JsonParser.Feature.EMPTY_STRING_AS_NULL does not work when text is parsed as String[] #222

Closed
wkwkhautbois opened this issue Sep 7, 2020 · 3 comments
Labels
Milestone

Comments

@wkwkhautbois
Copy link

CsvParser.Feature.EMPTY_STRING_AS_NULL not works when csv is parsed String[].
On the other hand, the feature is valid when csv is parsed as Object[].

String csv = "Grace,,Hopper";

CsvMapper csvMapper = CsvMapper.builder()
        .enable(CsvParser.Feature.EMPTY_STRING_AS_NULL)
        .enable(CsvParser.Feature.WRAP_AS_ARRAY)
        .build();

MappingIterator<Object[]> it1 =  csvMapper.readerFor(Object[].class).readValues(csv);
it1.hasNext();
Object[] array1= it1.next();

MappingIterator<String[]> it2 =  csvMapper.readerFor(String[].class).readValues(csv);
it2.hasNext();
String[] array2= it2.next();

System.out.println(Arrays.toString(array1));    // [Grace, null, Hopper]
System.out.println(Arrays.toString(array2));    // [Grace, , Hopper]      array2[1] is not null, but empty string ""

This is strange behavior and both case should parsed as null, I think.
Is this a bug?

jackson v.2.11.2

@cowtowncoder
Copy link
Member

@wkwkhautbois it does sound like a bug. Thank you for reporting this.

@cowtowncoder
Copy link
Member

Interesting. Yes, I can reproduce this; due to missing handling in CsvParser.nextTextValue() (and possibly databind's optimizations for String[] type, but we'll see about that). I think that there's some risk of regression so will target fix for 2.12.

@cowtowncoder cowtowncoder added 2.12 and removed 2.11 labels Sep 9, 2020
@cowtowncoder cowtowncoder changed the title CSV: EMPTY_STRING_AS_NULL does NOT work when text is parsed as String[] JsonParser.Feature.EMPTY_STRING_AS_NULL does not work when text is parsed as String[] Sep 9, 2020
@cowtowncoder cowtowncoder added this to the 2.12.0 milestone Sep 9, 2020
@wkwkhautbois
Copy link
Author

Thank you, I'm looking forward to next version release!

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

2 participants