Consider I have a CSV as such:
name,city,active
abc,bcde,t
xyz,ghj,f
If I wanted to map this to a model how would I convert the 't'
or 'f'
to proper booleans. I am using jackson-dataformat-csv
mapping to do this
CsvSchema csvSchema = CsvSchema.emptySchema().withHeader().withNullValue("");
CsvMapper csvMapper = new CsvMapper();
csvMapper.setPropertyNamingStrategy(SNAKE_CASE);
csvMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MappingIterator<Article> iterator = csvMapper.readerWithTypedSchemaFor(Object.class).with(csvSchema).readValues(fileFromResponse);
List<Object> data = iterator.readAll();
Currently the mapping fails with this error message:
Cannot deserialize value of type `java.lang.Boolean` from String "t": only "true" or "false" recognized
Is there any way I can specify in the schema that 't' or 'f' should be taken as booleans. Or is there another way I can deserialize it?