This does not compile, any suggestion appreciated.
... List list = getList(); return (List) list;
Compil
List testNovedads = crudService.createNativeQuery( "SELECT ID_NOVEDAD_PK, OBSERVACIONES, ID_SOLICITUD_PAGO_FK FROM DBSEGUIMIENTO.SC_NOVEDADES WHERE ID_NOVEDAD_PK < 2000"); Convertir convertir = new Convertir(); Collection novedads = convertir.toList(testNovedads, TestNovedad.class); for (TestNovedad testNovedad : novedads) { System.out.println(testNovedad.toString()); } public Collection toList(List objects, Class type) { Gson gson = new Gson(); JSONObject jsonObject = new JSONObject(); Collection collection = new ArrayList<>(); Field[] fields = TestNovedad.class.getDeclaredFields(); for (Object[] object : objects) { int pos = 0; for (Field field : fields) { jsonObject.put(field.getName(), object[pos++]); } collection.add(gson.fromJson(jsonObject.toString(), type)); } return collection; }