model/src/main/java/eu/internetofus/common/model/Model.java
/**
   * Obtain the model associated to a future {@link JsonArray}.
   *
   * @param futureArray the future array of the model.
   * @param type        of model to obtain.
   *
   * @param <T>         type of model.
   *
   * @return the future model defined on the array.
   */
Obtain the model associated to a future  JsonArray.
@param futureArray the future array of the model.
@param type        of model to obtain.

@param          type of model.

@return the future model defined on the array.
Obtain the model associated to a future JsonArray . @param futureArray the future array of the model . @param type of model to obtain . @param type of model . @return the future model defined on the array .
@SuppressWarnings("unchecked")
  public static <T> Future<List<T>> fromFutureJsonArray(@NotNull final Future<JsonArray> futureArray,
      @NotNull final Class<T> type) {
    return futureArray.compose(array -> {
      final var values = new ArrayList<T>();
      if (array != null) {
        try {
          final var max = array.size();
          for (var i = 0; i < max; i++) {
            final var element = array.getValue(i);
            if (type.isInstance(element) || element == null) {
              values.add((T) element);
            } else if (element instanceof ClusterSerializable) {
              final var buffer = Json.encodeToBuffer(element);
              final var value = Json.decodeValue(buffer, type);
              values.add(value);
            } else {
              return Future.failedFuture("The value '" + element + "' at '" + i + "' is not of the expected type '"
                  + type.getSimpleName() + "'.");
            }
          }
        } catch (final Throwable throwable) {
          return Future.failedFuture(throwable);
        }
      }
      return Future.succeededFuture(values);
    });
  }
@ SuppressWarnings ( "unchecked" ) public static < T > Future < List < T > > fromFutureJsonArray ( @ NotNull final Future < JsonArray > futureArray , @ NotNull final Class < T > type ) { return futureArray . compose ( array -> { final var values = new ArrayList < T > ( ) ; if ( array != null ) { try { final var max = array . size ( ) ; for ( var i = 0 ; i < max ; i ++ ) { final var element = array . getValue ( i ) ; if ( type . isInstance ( element ) || element == null ) { values . add ( ( T ) element ) ; } else if ( element instanceof ClusterSerializable ) { final var buffer = Json . encodeToBuffer ( element ) ; final var value = Json . decodeValue ( buffer , type ) ; values . add ( value ) ; } else { return Future . failedFuture ( "The value '" + element + "' at '" + i + "' is not of the expected type '" + type . getSimpleName ( ) + "'." ) ; } } } catch ( final Throwable throwable ) { return Future . failedFuture ( throwable ) ; } } return Future . succeededFuture ( values ) ; } ) ; }
Obtain the model associated to a future {@link JsonArray}.
Obtain the model associated to a future { @link JsonArray } .