'I wrote a program for Excel to JSON but it's giving NULL in output. How can I change the code so that it give output instead NULL

The problem with this code is that it's giving NULL in output. How can I print values in output.

Here I created a class ExcelReader in Maven.

public class ExcelReader {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
try {
            
            FileInputStream file = new FileInputStream( new File("C:\\Users\\Ankit Prakash\\Downloads\\BRs automated project creation DRAFT.xlsx"));
            XSSFWorkbook workbook = new XSSFWorkbook(file);
            XSSFSheet sheet = workbook.getSheetAt(1);
            Iterator<Row> rowIterator = sheet.rowIterator();
            int i=0; 
            
            while(rowIterator.hasNext()) {
                
                Row row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();
                
                int j=0;
                while(cellIterator.hasNext()) {
                    
                
                Cell cell = cellIterator.next();

"POJO":-Here I created a pojo class and used getter and setters.


                PojoClassName pcn = new PojoClassName(); 
                
        
                // switch(cell.getCellType()) {
                
            //    case NUMERIC: System.out.println(cell.getNumericCellValue()+"\t");
                 //                   break;
                // case STRING: System.out.println(cell.getStringCellValue()+"\t");
                             //       break;        
                                    
                                    if(i==0) {
                                        pcn.setTitle(cell.getStringCellValue());
                                        System.out.println("pcn.toString");
                                        i++;
                                        break;
                                        }
                                    else if(i==1) {
                                        pcn.setType(cell.getStringCellValue());
                                        System.out.println("pcn.toString");
                                        i++;
                                        break;
                                    }
                                    else if(i==2) {
                                        pcn.setStatus(cell.getStringCellValue());
                                        System.out.println("pcn.toString");
                                        i++;
                                        break;
                                    }
                                    else if(i==3) {
                                        pcn.setVersion(cell.getStringCellValue());
                                        System.out.println("cell.getStringCellValue");
                                        i++;
                                        break;
                                        }
                                    else if(i==4) {
                                        pcn.setLinkType(cell.getStringCellValue());
                                        System.out.println("cell.getStringCellValue");
                                        i++;
                                        break;
                                    }
                                    else if(i==5) {
                                        pcn.ProgrammeName(cell.getStringCellValue());
                                        System.out.println("cell.getStringCellValue");
                                        i++;
                                        break;
                                                     
                }
"Jackson":- here I used object mapper for converting excel to JSON
            
                                    //System.out.println(pcn.toString());
                                    ObjectMapper mapper = new ObjectMapper();

                               

                                    String json = mapper.writeValueAsString(pcn);
                                    System.out.println(json);
                }
            }
                System.out.println("");
                System.out.println("============================================");
            
        //  }

            
            
            file.close();
        }catch(Exception e) {
            e.printStackTrace();
            System.out.println();
        }
}
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source