Parse CSV with extra columns which are not defined in POJO

18 views
Skip to first unread message

Shubham Goyal

unread,
Apr 13, 2022, 3:58:11 AM4/13/22
to jackson-user
Hello,

I am trying to parse a CSV and serialize it using the Jackson library. I have tried several methods but can't get to ignore the extra columns in the CSV which are not defined in the POJO. The CSV comes in realtime from a server. 

Requirements:

  1. The columns in the incoming CSV can be in any order.
  2. There can be some columns which are defined in POJO but not there in CSV (missing columns).
  3. There can be some columns in the CSV which are not defined in POJO (extra columns at any index).

I have already tried @JsonIgnoreProperties(true) and also tried to use DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES but nothing seems to work properly.

POJO:

public class student{ 
  @JsonProperty("STUDENT_NAME") 
  private String name; 
  @JsonProperty("DOB") 
  private String dateOfBirth; 
  @JsonProperty("ID") 
  private String id; 
}

CSV:

STUDENT_NAME,ID,STANDARD,DOB 
John,1,4,01/02/2000 
Doe,2,5,02/01/1999

Please let me know how I can get all the above 3 requirements fulfilled. 

Thanks, 
Shubham   
Reply all
Reply to author
Forward
0 new messages