Class TypedJavaScriptResultUtil

java.lang.Object
com.vaadin.flow.component.internal.TypedJavaScriptResultUtil

public final class TypedJavaScriptResultUtil extends Object
Adds handlers to a pending JavaScript result that decode its JSON value to a Java type. A value that can not be decoded is reported as an error instead of being thrown from the handler, since the pending result chains the handlers added to it, so throwing would also skip any added after this one, and a future waiting for the value would never complete.

For internal use only. May be renamed or removed in a future release.

Since:
25.4
  • Method Details

    • then

      public static <T> void then(PendingJavaScriptResult pending, SerializableFunction<tools.jackson.databind.JsonNode,T> decoder, SerializableConsumer<T> resultHandler, SerializableConsumer<String> errorHandler)
      Adds a handler for the decoded value of a successful execution and a handler for a failed execution or a value that can not be decoded.
      Type Parameters:
      T - the decoded type
      Parameters:
      pending - the pending result to add the handlers to, not null
      decoder - the function that decodes the JSON value, throwing an IllegalArgumentException if it can not, not null
      resultHandler - a handler for the decoded value, not null
      errorHandler - a handler for an error message in case the execution failed or its value can not be decoded, or null to ignore errors
    • toCompletableFuture

      public static <T> CompletableFuture<T> toCompletableFuture(PendingJavaScriptResult pending, SerializableFunction<tools.jackson.databind.JsonNode,T> decoder)
      Creates a completable future that is completed with the decoded value of a successful execution. It is completed exceptionally with a PendingJavaScriptResult.JavaScriptException if the execution fails, or if the value can not be decoded, in which case the cause is the IllegalArgumentException from decoding.
      Type Parameters:
      T - the decoded type
      Parameters:
      pending - the pending result to add the handlers to, not null
      decoder - the function that decodes the JSON value, throwing an IllegalArgumentException if it can not, not null
      Returns:
      a completable future that will be completed based on the execution results, not null