From 42841decd1ef5ec1f7c35ac4839548c557b57ea2 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 3 Apr 2023 01:39:13 -0400 Subject: [PATCH] Async Generic Reflect Type --- .../java/io/avaje/http/client/DHttpAsync.java | 14 +++---- .../java/io/avaje/http/client/DHttpCall.java | 38 +++++++++---------- .../avaje/http/client/HttpAsyncResponse.java | 20 +++++----- .../avaje/http/client/HttpCallResponse.java | 14 +++---- .../avaje/http/client/HttpClientRequest.java | 2 +- .../avaje/http/client/HttpClientResponse.java | 14 +++---- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/http-client/src/main/java/io/avaje/http/client/DHttpAsync.java b/http-client/src/main/java/io/avaje/http/client/DHttpAsync.java index c69638438..a4f150350 100644 --- a/http-client/src/main/java/io/avaje/http/client/DHttpAsync.java +++ b/http-client/src/main/java/io/avaje/http/client/DHttpAsync.java @@ -1,7 +1,7 @@ package io.avaje.http.client; import java.io.InputStream; -import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.net.http.HttpResponse; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -65,7 +65,7 @@ public CompletableFuture bean(Class type) { } @Override - public CompletableFuture bean(ParameterizedType type) { + public CompletableFuture bean(Type type) { final CompletableFuture> future = as(type); return future.thenApply(HttpResponse::body); } @@ -76,7 +76,7 @@ public CompletableFuture> as(Class type) { } @Override - public CompletableFuture> as(ParameterizedType type) { + public CompletableFuture> as(Type type) { return asyncAsBytes().thenApply(httpResponse -> request.asyncBean(type, httpResponse)); } @@ -86,7 +86,7 @@ public CompletableFuture> list(Class type) { } @Override - public CompletableFuture> list(ParameterizedType type) { + public CompletableFuture> list(Type type) { final CompletableFuture>> future = asList(type); return future.thenApply(HttpResponse::body); } @@ -97,7 +97,7 @@ public CompletableFuture>> asList(Class type) { } @Override - public CompletableFuture>> asList(ParameterizedType type) { + public CompletableFuture>> asList(Type type) { return asyncAsBytes().thenApply(httpResponse -> request.asyncList(type, httpResponse)); } @@ -107,7 +107,7 @@ public CompletableFuture> stream(Class type) { } @Override - public CompletableFuture> stream(ParameterizedType type) { + public CompletableFuture> stream(Type type) { final CompletableFuture>> future = asStream(type); return future.thenApply(HttpResponse::body); } @@ -118,7 +118,7 @@ public CompletableFuture>> asStream(Class type) { } @Override - public CompletableFuture>> asStream(ParameterizedType type) { + public CompletableFuture>> asStream(Type type) { return asyncAsLines().thenApply(httpResponse -> request.asyncStream(type, httpResponse)); } diff --git a/http-client/src/main/java/io/avaje/http/client/DHttpCall.java b/http-client/src/main/java/io/avaje/http/client/DHttpCall.java index 7882c0664..1a5a667e5 100644 --- a/http-client/src/main/java/io/avaje/http/client/DHttpCall.java +++ b/http-client/src/main/java/io/avaje/http/client/DHttpCall.java @@ -1,7 +1,7 @@ package io.avaje.http.client; import java.io.InputStream; -import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.net.http.HttpResponse; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -61,7 +61,7 @@ public HttpCall> as(Class type) { } @Override - public HttpCall> as(ParameterizedType type) { + public HttpCall> as(Type type) { return new CallAs<>(type); } @@ -71,7 +71,7 @@ public HttpCall>> asList(Class type) { } @Override - public HttpCall>> asList(ParameterizedType type) { + public HttpCall>> asList(Type type) { return new CallAsList<>(type); } @@ -81,7 +81,7 @@ public HttpCall>> asStream(Class type) { } @Override - public HttpCall>> asStream(ParameterizedType type) { + public HttpCall>> asStream(Type type) { return new CallAsStream<>(type); } @@ -96,17 +96,17 @@ public HttpCall> stream(Class type) { } @Override - public HttpCall bean(ParameterizedType type) { + public HttpCall bean(Type type) { return new CallBean<>(type); } @Override - public HttpCall> list(ParameterizedType type) { + public HttpCall> list(Type type) { return new CallList<>(type); } @Override - public HttpCall> stream(ParameterizedType type) { + public HttpCall> stream(Type type) { return new CallStream<>(type); } @@ -184,7 +184,7 @@ public CompletableFuture> async() { private class CallAs implements HttpCall> { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallAs(Class type) { @@ -193,7 +193,7 @@ private class CallAs implements HttpCall> { this.genericType = null; } - CallAs(ParameterizedType type) { + CallAs(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; @@ -212,7 +212,7 @@ public CompletableFuture> async() { private class CallAsList implements HttpCall>> { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallAsList(Class type) { @@ -221,7 +221,7 @@ private class CallAsList implements HttpCall>> { this.genericType = null; } - CallAsList(ParameterizedType type) { + CallAsList(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; @@ -240,7 +240,7 @@ public CompletableFuture>> async() { private class CallAsStream implements HttpCall>> { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallAsStream(Class type) { @@ -249,7 +249,7 @@ private class CallAsStream implements HttpCall>> { this.genericType = null; } - CallAsStream(ParameterizedType type) { + CallAsStream(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; @@ -268,7 +268,7 @@ public CompletableFuture>> async() { private class CallBean implements HttpCall { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallBean(Class type) { @@ -277,7 +277,7 @@ private class CallBean implements HttpCall { this.genericType = null; } - CallBean(ParameterizedType type) { + CallBean(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; @@ -296,7 +296,7 @@ public CompletableFuture async() { private class CallList implements HttpCall> { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallList(Class type) { @@ -305,7 +305,7 @@ private class CallList implements HttpCall> { this.genericType = null; } - CallList(ParameterizedType type) { + CallList(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; @@ -324,7 +324,7 @@ public CompletableFuture> async() { private class CallStream implements HttpCall> { private final Class type; - private final ParameterizedType genericType; + private final Type genericType; private final boolean isGeneric; CallStream(Class type) { @@ -333,7 +333,7 @@ private class CallStream implements HttpCall> { this.genericType = null; } - CallStream(ParameterizedType type) { + CallStream(Type type) { this.isGeneric = true; this.type = null; this.genericType = type; diff --git a/http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java b/http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java index a7ec8e3db..ca39b400b 100644 --- a/http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java +++ b/http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java @@ -1,7 +1,7 @@ package io.avaje.http.client; import java.io.InputStream; -import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.net.http.HttpResponse; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -270,7 +270,7 @@ default CompletableFuture> withHandler(HttpResponse.BodyHand /** * The same as {@link #as(Class)} but using a generic type. */ - CompletableFuture> as(ParameterizedType type); + CompletableFuture> as(Type type); /** * Process expecting a bean response body (typically from json content). @@ -346,7 +346,7 @@ default CompletableFuture> withHandler(HttpResponse.BodyHand /** * The same as {@link #asList(Class)} but using a generic type. */ - CompletableFuture>> asList(ParameterizedType type); + CompletableFuture>> asList(Type type); /** * Process expecting a list of beans response body (typically from json content). @@ -419,7 +419,7 @@ default CompletableFuture> withHandler(HttpResponse.BodyHand /** * The same as {@link #asStream(Class)} but using a generic type. */ - CompletableFuture>> asStream(ParameterizedType type); + CompletableFuture>> asStream(Type type); /** * Process response as a stream of beans (x-json-stream). @@ -463,25 +463,25 @@ default CompletableFuture> withHandler(HttpResponse.BodyHand /** * Process expecting a bean response body (typically from json content). * - * @param type The parameterized type to convert the content to + * @param type The type to convert the content to * @return The CompletableFuture of the response */ - CompletableFuture bean(ParameterizedType type); + CompletableFuture bean(Type type); /** * Process expecting a list of beans response body (typically from json content). * - * @param type The parameterized type to convert the content to + * @param type The type to convert the content to * @return The CompletableFuture of the response */ - CompletableFuture> list(ParameterizedType type); + CompletableFuture> list(Type type); /** * Process response as a stream of beans (x-json-stream). * - * @param type The parameterized type to convert the content to + * @param type The type to convert the content to * @return The CompletableFuture of the response */ - CompletableFuture> stream(ParameterizedType type); + CompletableFuture> stream(Type type); } diff --git a/http-client/src/main/java/io/avaje/http/client/HttpCallResponse.java b/http-client/src/main/java/io/avaje/http/client/HttpCallResponse.java index 9001106b9..51040422d 100644 --- a/http-client/src/main/java/io/avaje/http/client/HttpCallResponse.java +++ b/http-client/src/main/java/io/avaje/http/client/HttpCallResponse.java @@ -1,7 +1,7 @@ package io.avaje.http.client; import java.io.InputStream; -import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.net.http.HttpResponse; import java.util.List; import java.util.stream.Stream; @@ -150,7 +150,7 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo /** * Same as {@link #as(Class)} but takes a generic parameterized type. */ - HttpCall> as(ParameterizedType type); + HttpCall> as(Type type); /** * Same as {@link #as(Class)} but returns {@code HttpResponse>}. @@ -160,7 +160,7 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo /** * Same as {@link #as(Class)} but returns {@code HttpResponse>}. */ - HttpCall>> asList(ParameterizedType type); + HttpCall>> asList(Type type); /** * Same as {@link #as(Class)} but returns {@code HttpResponse>}. @@ -170,7 +170,7 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo /** * Same as {@link #as(Class)} but returns {@code HttpResponse>}. */ - HttpCall>> asStream(ParameterizedType type); + HttpCall>> asStream(Type type); /** * A bean response to execute async or sync. @@ -239,7 +239,7 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo * @param type The parameterized type to convert the content to * @return The HttpCall to allow sync or async execution */ - HttpCall bean(ParameterizedType type); + HttpCall bean(Type type); /** * Process expecting a list of beans response body (typically from json content). @@ -247,7 +247,7 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo * @param type The parameterized type to convert the content to * @return The HttpCall to execute sync or async */ - HttpCall> list(ParameterizedType type); + HttpCall> list(Type type); /** * Process expecting a stream of beans response body (typically from json content). @@ -255,6 +255,6 @@ default HttpCall> withHandler(HttpResponse.BodyHandler bo * @param type The parameterized type to convert the content to * @return The HttpCall to execute sync or async */ - HttpCall> stream(ParameterizedType type); + HttpCall> stream(Type type); } diff --git a/http-client/src/main/java/io/avaje/http/client/HttpClientRequest.java b/http-client/src/main/java/io/avaje/http/client/HttpClientRequest.java index fd31804d5..44c2ac230 100644 --- a/http-client/src/main/java/io/avaje/http/client/HttpClientRequest.java +++ b/http-client/src/main/java/io/avaje/http/client/HttpClientRequest.java @@ -321,7 +321,7 @@ default HttpClientRequest queryParam(String name, Collection values) { * a type that is known to JsonbAdapter / the body content adapter used. * * @param bean The body content as an instance - * @param type The parameterized type used by the body content adapter to write the body content + * @param type The type used by the body content adapter to write the body content * @return The request being built */ HttpClientRequest body(Object bean, Type type); diff --git a/http-client/src/main/java/io/avaje/http/client/HttpClientResponse.java b/http-client/src/main/java/io/avaje/http/client/HttpClientResponse.java index 39523aea7..299e0bb98 100644 --- a/http-client/src/main/java/io/avaje/http/client/HttpClientResponse.java +++ b/http-client/src/main/java/io/avaje/http/client/HttpClientResponse.java @@ -74,12 +74,12 @@ public interface HttpClientResponse { HttpResponse as(Class type); /** - * Return the response with the body containing a single instance of the given parameterized type. + * Return the response with the body containing a single instance of the given type. *

* If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains * the HttpResponse. This is the cause in the CompletionException when using an async request. * - * @param type The parameterized type of the bean to convert the response content into. + * @param type The type of the bean to convert the response content into. * @return The response containing the converted body. * @throws HttpException when the response has error status codes */ @@ -99,7 +99,7 @@ public interface HttpClientResponse { HttpResponse> asList(Class type); /** - * Return the response with the body containing a list of the given parameterized type. + * Return the response with the body containing a list of the given type. *

* If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains * the HttpResponse. This is the cause in the CompletionException when using an async request. @@ -133,7 +133,7 @@ public interface HttpClientResponse { HttpResponse> asStream(Class type); /** - * Return the response with the body containing a stream of beans of the given parameterized type. + * Return the response with the body containing a stream of beans of the given type. *

* Typically the response is expected to be {@literal application/x-json-stream} * newline delimited json payload. @@ -206,7 +206,7 @@ public interface HttpClientResponse { * If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains * the HttpResponse. This is the cause in the CompletionException when using an async request. * - * @param type The parameterized type of the bean to convert the response content into. + * @param type The type of the bean to convert the response content into. * @return The bean the response is converted into. * @throws HttpException when the response has error status codes */ @@ -218,7 +218,7 @@ public interface HttpClientResponse { * If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains * the HttpResponse. This is the cause in the CompletionException when using an async request. * - * @param type The parameterized type of the bean to convert the response content into. + * @param type The type of the bean to convert the response content into. * @return The list of beans the response is converted into. * @throws HttpException when the response has error status codes */ @@ -238,7 +238,7 @@ public interface HttpClientResponse { * If the HTTP statusCode is not in the 2XX range a HttpException is throw which contains * the HttpResponse. This is the cause in the CompletionException when using an async request. * - * @param type The parameterized type of the bean to convert the response content into. + * @param type The type of the bean to convert the response content into. * @return The stream of beans from the response * @throws HttpException when the response has error status codes */