Home > Enterprise >  How to convert List<Object[]> into List<List<Object>> for GoogleSheet ValueRange
How to convert List<Object[]> into List<List<Object>> for GoogleSheet ValueRange

Time:10-27

I am trying to write report from hibernate resultset which returns result as List<Object[]> In order to send this data to google sheet API I need to convert it into List<List> I have tried several ways but getting following error

"message" : "Invalid data[1]: Invalid values[1][0]: list_value

following is the code I tried but no luck

It might a very dumb thing to ask here but anyone if possible please help

List<Object> allData = new ArrayList<>();
      List<List<Object>> values = new ArrayList<>();
      for (Object[] obj : reportParameters.getDataSource().getResultSet()){
        allData.add(Arrays.asList(obj));
      }
      values.add(allData);
      ValueRange sheetData = new ValueRange()
          .setValues(values)
          .setRange("A2");
      body.add(sheetData);

CodePudding user response:

List<List<Object>> values = reportParameters.getDataSource().getResultSet()
   .stream()
   .map(Arrays::asList)
   .collect(Collectors.toList());
  • Related