How to have a required column but a nullable content
Brought to you by:
aruckerjones,
sconway
Hello,
Using a CsvToBeanBuilder, I wish to know if there is a way to have a required column (named column must present in the source CSV) but with a nullable content.
Apparently, CsvBindByName "required" attribute forces both.
Regards
Alberto
Hello Alberto
Sorry it took so long to get back to you but life has been busy :)
So you only care that the column is present but not about the data.
Honestly I would just create a CSVReader and read the header line and check the array for the value and then close that reader. If the header array has the value then create your StatefulCsvToBean with any mapping strategy other than the HeaderColumnNameMappingStrategy - because that is the one that is checking the required annotation.
Or you can use the mapping strategy. I have created and committed a SR113Test that you can look at for an example. I used the HeaderColumnNameMappingStrategy and give it two tests: one with a string with a required field and the other that is missing the field. And then I use the strategy to give me the header and check if it contains the field I want.
Hope that helps
closed for lack of response.