Search code examples
univocity

Univocity parser using routines ignores the LongCoversion using defaultNullRead attribute?


I have below field configuration:

@Parsed(field="TEST_ID", defaultNullRead="000000")
private Long testId

now when the input file (csv parsing) contains value as NULL, it is not converting to default long value of 0, rather throws LongConversion exception for "NULL"

e.g. row in csv file: (5th column containing NULL is an issue)

7777|ab|444|PENDING|NULL|VESRION|TEST|11

I am using csvRoutines for parsing the input csv file


Solution

  • NULL in your input is actually text and not Java's null. You need to tell the parser to translate the string NULL to java null.

    Add the following annotation (you can give it more than one string that represents null:

    @NullString(nulls = {"NULL", "N/A", "?"})

    Hope this helps