Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Parsing CSV into beans with opencsv in Java

I am trying to parse .csv files into where one of the columns is structured like this: [123.123]. I only need the numbers for a field in my Java bean. The field class looks like this:

@CsvBindByName(column = "Random.Param.", required = true, capture="([^\\]\\[]*)")
@Column(name="RANDOM_PARAM")
private float randomParam;

According to the docs here : http://opencsv.sourceforge.net/#annotations_2 regex I added at the capture of @CsvBindByName annotation should be enough to get the job done. However it seems that the parser is ignoring the regex and it is trying to parse the number with brackets into float :

Caused by: java.lang.NumberFormatException: For input string: "[1626.87]"

The following line starts the parser:

List<Record> beans = new CsvToBeanBuilder(new FileReader(pathToFile)).withType(Record.class).withSeparator(';').build().parse();

Is there anything extra I have to do to get opencsv parser to ignore the brackets?

Comments