3

I am using camel-bindy to unmarshall a CSV to Java Object. Is it possible to ignore a particular column? Consider following example, I don't want to map column 3 (Address). Please let me know if there is a way to do so. In reality I have more than 10 columns in my CSV that I want to ignore.

Example :- CSV File:

 Header   : Name,Mobile,Address
 Data Row : Rabbit,007,Rabbit Hole

Bindy mapping in Java class:

@CsvRecord(separator = "," , skipFirstLine = true) 
public class Contacts {

@DataField(pos = 1, trim=true)
private String name;

@DataField(pos = 2, required = true, trim=true) 
private Long Mobile;

Thanks for your time!

mdnghtblue
  • 1,117
  • 8
  • 27
Techie Rabbit
  • 33
  • 1
  • 5

2 Answers2

4

The latest version supports skipField

@CsvRecord(separator = ",",skipField =true)

1

You cannot skip a column. Bindy iterates through every token and checks if there is an associated data field, see BindyCsvFactory:

// Get DataField from model
DataField dataField = dataFields.get(pos);
ObjectHelper.notNull(dataField, "No position " + pos + " defined for the field: " + data + ", line: " + line);

The only solution is to define a class attribute that is just ignored:

@DataField(pos = 1)
public String ingoreMe;
Peter Keller
  • 7,526
  • 2
  • 26
  • 29
  • Thanks for your reply. I looked at BindyCsvFactory before posting the question. But I was hoping that there must be another way or a workaround for my requirement. I tried to move to BeanIO but there it seems the header cannot be easily skipped like in Bindy. Thanks. – Techie Rabbit Nov 20 '14 at 10:23