I am using opencsv to create a CsvToBean
like this:
CsvToBean<AccountBean> csvToBean = new CsvToBeanBuilder<AccountBean>(new InputStreamReader(inputStream))
.withFieldAsNull(CSVReaderNullFieldIndicator.NEITHER)
.withType(AccountBean.class)
.build();
And this is my AccountBean
:
public class AccountBean extends BeanBase<Account>
{
@CsvBindByName(column = "Id", required = true)
public String salesforceId;
@CsvBindByName(column = "OwnerId", required = true)
public String ownerId;
@CsvBindByName(column = "Name", required = true)
public String name;
// billing address
@CsvBindByName(column = "BillingStreet")
String billingStreet;
@CsvBindByName(column = "BillingCity")
String billingCity;
@CsvBindByName(column = "BillingState")
String billingState;
@CsvBindByName(column = "BillingPostalCode")
String billingPostcode;
@CsvBindByName(column = "BillingCountry")
String billingCountry;
}
The issue is with the address fields - if there is a blank field, they are ALWAYS null, regardless of which CSVReaderNullFieldIndicator
value I pass to .withFieldAsNull()
.
My csv file has double quotes to denote an empty field, so using CSVReaderNullFieldIndicator.NEITHER (which is default anyway) should produce an empty String.
This is causing issues as I'm saving nulls to my datastore and then it's causing NullPointerExceptions later.
An I doing something wrong?