Class TypedJavaScriptResultUtil
java.lang.Object
com.vaadin.flow.component.internal.TypedJavaScriptResultUtil
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 Summary
Modifier and TypeMethodDescriptionstatic <T> voidthen(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.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.
-
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, notnulldecoder- the function that decodes the JSON value, throwing anIllegalArgumentExceptionif it can not, notnullresultHandler- a handler for the decoded value, notnullerrorHandler- a handler for an error message in case the execution failed or its value can not be decoded, ornullto 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 aPendingJavaScriptResult.JavaScriptExceptionif the execution fails, or if the value can not be decoded, in which case the cause is theIllegalArgumentExceptionfrom decoding.- Type Parameters:
T- the decoded type- Parameters:
pending- the pending result to add the handlers to, notnulldecoder- the function that decodes the JSON value, throwing anIllegalArgumentExceptionif it can not, notnull- Returns:
- a completable future that will be completed based on the
execution results, not
null
-