2

For fixed width parsing using multiple lookahead, the empty string causes issues (i.e., fieldX=' '). So for fixed format file with only 2 records, if the first record ends with a empty string field, then this causes a issue. The last field in the record is treated as empty(null), and it does not treat the first character in the next record as a lookahead, but instead the second character. If the last field in the first record has a non-empty value (fieldX='11111'), then this is not an issue and it works. The workaround for me was to set settings.getFormat().setPadding('~') to some character not expected in the file.

Is there any settings to allow to accept empty strings and treat them as ' ' and not NULL.

Please advise.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
user518066
  • 1,277
  • 3
  • 23
  • 35

1 Answers1

1

Author of the library here.

Does settings().setNullValue(""); help?

If not, can you please updated your post to include a sample of the input and the code you are using to parse it so I can reproduce this and check?

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29
  • Thanks, but that did not work, as last field in first record has x number of blank spaces. So if I have a field with 5 spaces, I want it to appear as 5 spaces in record as it is fixed format. – user518066 Jul 12 '18 at 08:05
  • Also, if last field is treated as NULL, then the look ahead of the next record should begin on first character of second record, but instead it goes to second character. – user518066 Jul 12 '18 at 08:19
  • @user518066 it looks like you should disable trimming whitespaces. Use: `settings.trimValues(false);` as well and let me know how that goes. – Jeronimo Backes Jul 12 '18 at 10:09
  • already tried settings.trimValues(false), but that did not fix. – user518066 Jul 12 '18 at 12:49
  • Ok can you please update your question to include a sample of the input and the code you are using to parse it so I can reproduce this and check? – Jeronimo Backes Jul 12 '18 at 12:50
  • Using the settings.trimValues(false); worked for me, thanks. – Big D. Nov 22 '19 at 15:34