code: @SuppressWarnings("PMD.LooseCoupling")
      public static Object convertToArray(final Object result, final Class entityType, final boolean projection) {
          final Collection res = result instanceof Collection
                  // no projection because its applied later
                  ? (Collection) result : convertToCollectionImpl(result, ArrayList.class, entityType, false);
          final Object array = Array.newInstance(entityType, res.size());
          int i = 0;
          for (Object obj : res) {
              Array.set(array, i++, projection ? applyProjection(obj, entityType) : obj);
          }
          return array;
      }
docs: Convert result object to array.
  
  @param result     result object
  @param entityType target entity type
  @param projection true to apply projection, false otherwise
  @return converted result