0

I am getting null for one of the selected column with IterableCSVToBean<MessageFileExtractHeader>

DTO Classe:

public class MessageFileExtractHeader implements Serializable {

    private static final long serialVersionUID = -3052197544136826142L;

    private String mesgid;
    private String mesg_type;

 // getters and setters

Main Class:

public class FileExtraction {

    public static void main(String[] args) throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException, IntrospectionException, CsvBadConverterException, CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException {
        Properties prop = new Properties();
        ExtractFieldUtils efUtils= new ExtractFieldUtils();

        MessageFileExtractHeader msgFilxtractRecord = null;


        try {
              InputStream inputStream =
                      SAADumpFileExtraction.class.getClassLoader().getResourceAsStream("config.properties");
              prop.load(inputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
            String fileDirectory= prop.getProperty("file.directory");

            //get the filenames
            String mesgfilename= fileDirectory+prop.getProperty("mesg.file.name");


            //get the headers
            String mesgheader= fileDirectory+prop.getProperty("mesg.file.header.fields");


            int msgskiplines=1;


            CSVReader reader = null;
            try {
                reader = new CSVReader(new FileReader(mesgfilename));
                Map<String, String> msgmapping = efUtils.getMapping(mesgheader);
                HeaderColumnNameTranslateMappingStrategy<MessageFileExtractHeader> strategy = new HeaderColumnNameTranslateMappingStrategy<MessageFileExtractHeader>();
                strategy.setType(MessageFileExtractHeader.class);
                strategy.setColumnMapping(msgmapping);
                IterableCSVToBean<MessageFileExtractHeader> msgCTBIterator= new IterableCSVToBean<MessageFileExtractHeader>(reader, strategy, null);
                Iterator<MessageFileExtractHeader> mesgIterator= msgCTBIterator.iterator();
                while(mesgIterator.hasNext()){

                    msgFilxtractRecord = mesgIterator.next();
                    System.out.println(msgFilxtractRecord);


//                  
                }} finally {

                        reader.close();
                    }
                }               
}

Output:

MessageFileExtractHeaders [mesgid=null, mesg_type=081]

Please suggest me good solution to get the mesgid.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sam
  • 1
  • 1

1 Answers1

0

Please send an short sample of your csv file (header and one line) and the value of your header property.

My guess is there is a type in either the csv header, the headers in the property or both and it does not match what is in the DTO (mesgid). Because of that it will not be populated.

Scott Conway
  • 975
  • 7
  • 13