Hibernate Native Query This is my code to populate a Class and later convert it to JSON object.

public List&lt;CSATGraphJSON&gt; convertListToCSATGraphJSON(List&lt;Object[]&gt; list) throws ParseException{
        List&lt;CSATGraphJSON&gt; customers=new ArrayList&lt;CSATGraphJSON&gt;();
        //going through each list of object
        for (int i = 0; i &lt; list.size(); i++) {
            CSATGraphJSON graphJSON=new CSATGraphJSON();
            Object eachObject=list.get(i);
            int index=0;
            //iterating the each object array
            for(Object obj: (Object[]) eachObject){
                System.out.println(obj.toString());
                System.out.println(obj.getClass());
                switch(index){
                    case 0:{
                        if(obj!=null){
                            // if not null
                            /*DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
                            Date parsedDate = null;
                            parsedDate = df.parse(obj.toString());
                            // gives you java.util.Date
                            customerList.setResponsedatestr(parsedDate);*/
                            graphJSON.setX(obj.toString());
                        }
                        break;
                    }
                    case 1:{
                        if(obj!=null){
                            graphJSON.setVery_poor(Integer.parseInt(obj.toString()));
                        }
                        break;
                    }
                    case 2:{
                        if(obj!=null){
                            graphJSON.setPoor(Integer.parseInt(obj.toString()));
                        }
                        break;
                    }
                    case 3:{
                        if(obj!=null){
                            graphJSON.setAverage(Integer.parseInt(obj.toString()));
                        }                       
                        break;
                    }
                    case 4:{
                        if(obj!=null){
                            graphJSON.setGood(Integer.parseInt(obj.toString()));
                        }                       
                        break;
                    }
                    case 5:{
                        if(obj!=null){
                            graphJSON.setVery_good(Integer.parseInt(obj.toString()));
                        }                       
                        break;
                    }
                    case 6:{
                        if(obj!=null){
                            graphJSON.setTotal(Integer.parseInt(obj.toString()));
                        }                       
                        break;
                    }
                    default:{
                        break;
                    }
                }
                index++;

            }
            customers.add(graphJSON);
        }


        return customers;
    }


Here List list the result of createSQLQuery() in hibernate as it returns List of Object ,so it is converted to List of CSATGraphJSON object.

Please suggest any alternative method for the switch statement as it is making the code lengthy.
Naming

Java method names should not contain underscore characters. It's also preferable to use CamelCase even for abbreviations for readability (e.g. graphJson instead of graphJSON. convertListToCSATGraphJSON is pretty clumsy and could stand to be renamed for simplicity and clarity.

Implementation

I'm going to assume there's a good reason you're hand-rolling this. If not, hibernate has tools to help do this for you.

You have both for loops backwards. The first one should be an enhanced for-loop, and the second should be old-school.

There is absolutely no reason for the second for loop or the switch statement to exist. Just directly set the values by accessing the index number in the Object[] directly.

You may run into trouble later using a List&lt;Object[]&gt;. Generics and arrays do not play nicely together. Changing that is outside the scope of this review.

Small static helper methods can greatly clean up the variable assignments.

If you were to make all these changes, your code might look more like:

public List&lt;CSATGraphJSON&gt; convertListToCSATGraphJSON(final List&lt;Object[]&gt; list) throws ParseException {
    final List&lt;CSATGraphJSON&gt; customers = new ArrayList&lt;CSATGraphJSON&gt;();
    for (final Object[] objects : list) {
        final CSATGraphJSON graphJson = new CSATGraphJSON();
        graphJson.setX(parseString(objects[0]));
        graphJson.setVeryPoor(parseInt(objects[1]));
        graphJson.setPoor(parseInt(objects[2]));
        graphJson.setAverage(parseInt(objects[3]));
        graphJson.setGood(parseInt(objects[4]));
        graphJson.setVeryGood(parseInt(objects[5]));
        graphJson.setTotal(parseInt(objects[6]));
        customers.add(graphJson);
    }

    return customers;
}

private static String parseString(final Object o) {
    if (o == null) {
        return null;
    }
    return o.toString();
}

private static int parseInt(final Object o) {
    if (o == null) {
        return 0;
    }
    return Integer.parseInt(o.toString());
}