Search code examples
spring-batchopencsv

Spring Batch Linemapper for reading a CSV file which can have multiple columns with the same name


The requirement is to read and apply certain analytical functions on the Jira extracts for several projects(in order of 100s) in the organization. The Jira extract function exports the CSV file which can have multiple columns with the same name e.g., Comments, Attachments, Components.

In the POC phase, I was reading the CSV files using OpenCSV but I found out that it doesn't offer performance optimization techniques like Spring Batch does.

enter image description here

The tickets can have any number components, comment & attachment columns. Does Spring batch have a Linemapper which can map this data to a OpenCSV Bean as follows:

public class JiraInboundRecord {

    @CsvBindByName(column = "Issue key")
    private String issueKey;

    @CsvBindByName(column = "Description")
    private String description;

    @CsvBindAndJoinByName(column = "comments*", elementType = String.class)
    private MultiValuedMap<String, String> comments;
    
    @CsvBindAndJoinByName(column = "Components*", elementType = String.class)
    private MultiValuedMap<String, String> components;  

    @CsvBindAndJoinByName(column = "Attachments*", elementType = String.class)
    private MultiValuedMap<String, String> attachments;

Solution

  • Does Spring batch have a Linemapper which can map this data to a OpenCSV Bean

    No, there is no built-in LineMapper for OpenCSV. You need to create a custom one.