Skip to content

[http client] Change Async API to use more generic Type instead of ParameterizedType #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions http-client/src/main/java/io/avaje/http/client/DHttpAsync.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -65,7 +65,7 @@ public <E> CompletableFuture<E> bean(Class<E> type) {
}

@Override
public <E> CompletableFuture<E> bean(ParameterizedType type) {
public <E> CompletableFuture<E> bean(Type type) {
final CompletableFuture<HttpResponse<E>> future = as(type);
return future.thenApply(HttpResponse::body);
}
Expand All @@ -76,7 +76,7 @@ public <E> CompletableFuture<HttpResponse<E>> as(Class<E> type) {
}

@Override
public <E> CompletableFuture<HttpResponse<E>> as(ParameterizedType type) {
public <E> CompletableFuture<HttpResponse<E>> as(Type type) {
return asyncAsBytes().thenApply(httpResponse -> request.asyncBean(type, httpResponse));
}

Expand All @@ -86,7 +86,7 @@ public <E> CompletableFuture<List<E>> list(Class<E> type) {
}

@Override
public <E> CompletableFuture<List<E>> list(ParameterizedType type) {
public <E> CompletableFuture<List<E>> list(Type type) {
final CompletableFuture<HttpResponse<List<E>>> future = asList(type);
return future.thenApply(HttpResponse::body);
}
Expand All @@ -97,7 +97,7 @@ public <E> CompletableFuture<HttpResponse<List<E>>> asList(Class<E> type) {
}

@Override
public <E> CompletableFuture<HttpResponse<List<E>>> asList(ParameterizedType type) {
public <E> CompletableFuture<HttpResponse<List<E>>> asList(Type type) {
return asyncAsBytes().thenApply(httpResponse -> request.asyncList(type, httpResponse));
}

Expand All @@ -107,7 +107,7 @@ public <E> CompletableFuture<Stream<E>> stream(Class<E> type) {
}

@Override
public <E> CompletableFuture<Stream<E>> stream(ParameterizedType type) {
public <E> CompletableFuture<Stream<E>> stream(Type type) {
final CompletableFuture<HttpResponse<Stream<E>>> future = asStream(type);
return future.thenApply(HttpResponse::body);
}
Expand All @@ -118,7 +118,7 @@ public <E> CompletableFuture<HttpResponse<Stream<E>>> asStream(Class<E> type) {
}

@Override
public <E> CompletableFuture<HttpResponse<Stream<E>>> asStream(ParameterizedType type) {
public <E> CompletableFuture<HttpResponse<Stream<E>>> asStream(Type type) {
return asyncAsLines().thenApply(httpResponse -> request.asyncStream(type, httpResponse));
}

Expand Down
38 changes: 19 additions & 19 deletions http-client/src/main/java/io/avaje/http/client/DHttpCall.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -61,7 +61,7 @@ public <E> HttpCall<HttpResponse<E>> as(Class<E> type) {
}

@Override
public <E> HttpCall<HttpResponse<E>> as(ParameterizedType type) {
public <E> HttpCall<HttpResponse<E>> as(Type type) {
return new CallAs<>(type);
}

Expand All @@ -71,7 +71,7 @@ public <E> HttpCall<HttpResponse<List<E>>> asList(Class<E> type) {
}

@Override
public <E> HttpCall<HttpResponse<List<E>>> asList(ParameterizedType type) {
public <E> HttpCall<HttpResponse<List<E>>> asList(Type type) {
return new CallAsList<>(type);
}

Expand All @@ -81,7 +81,7 @@ public <E> HttpCall<HttpResponse<Stream<E>>> asStream(Class<E> type) {
}

@Override
public <E> HttpCall<HttpResponse<Stream<E>>> asStream(ParameterizedType type) {
public <E> HttpCall<HttpResponse<Stream<E>>> asStream(Type type) {
return new CallAsStream<>(type);
}

Expand All @@ -96,17 +96,17 @@ public <E> HttpCall<Stream<E>> stream(Class<E> type) {
}

@Override
public <E> HttpCall<E> bean(ParameterizedType type) {
public <E> HttpCall<E> bean(Type type) {
return new CallBean<>(type);
}

@Override
public <E> HttpCall<List<E>> list(ParameterizedType type) {
public <E> HttpCall<List<E>> list(Type type) {
return new CallList<>(type);
}

@Override
public <E> HttpCall<Stream<E>> stream(ParameterizedType type) {
public <E> HttpCall<Stream<E>> stream(Type type) {
return new CallStream<>(type);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public CompletableFuture<HttpResponse<InputStream>> async() {

private class CallAs<E> implements HttpCall<HttpResponse<E>> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallAs(Class<E> type) {
Expand All @@ -193,7 +193,7 @@ private class CallAs<E> implements HttpCall<HttpResponse<E>> {
this.genericType = null;
}

CallAs(ParameterizedType type) {
CallAs(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand All @@ -212,7 +212,7 @@ public CompletableFuture<HttpResponse<E>> async() {

private class CallAsList<E> implements HttpCall<HttpResponse<List<E>>> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallAsList(Class<E> type) {
Expand All @@ -221,7 +221,7 @@ private class CallAsList<E> implements HttpCall<HttpResponse<List<E>>> {
this.genericType = null;
}

CallAsList(ParameterizedType type) {
CallAsList(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand All @@ -240,7 +240,7 @@ public CompletableFuture<HttpResponse<List<E>>> async() {

private class CallAsStream<E> implements HttpCall<HttpResponse<Stream<E>>> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallAsStream(Class<E> type) {
Expand All @@ -249,7 +249,7 @@ private class CallAsStream<E> implements HttpCall<HttpResponse<Stream<E>>> {
this.genericType = null;
}

CallAsStream(ParameterizedType type) {
CallAsStream(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand All @@ -268,7 +268,7 @@ public CompletableFuture<HttpResponse<Stream<E>>> async() {

private class CallBean<E> implements HttpCall<E> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallBean(Class<E> type) {
Expand All @@ -277,7 +277,7 @@ private class CallBean<E> implements HttpCall<E> {
this.genericType = null;
}

CallBean(ParameterizedType type) {
CallBean(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand All @@ -296,7 +296,7 @@ public CompletableFuture<E> async() {

private class CallList<E> implements HttpCall<List<E>> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallList(Class<E> type) {
Expand All @@ -305,7 +305,7 @@ private class CallList<E> implements HttpCall<List<E>> {
this.genericType = null;
}

CallList(ParameterizedType type) {
CallList(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand All @@ -324,7 +324,7 @@ public CompletableFuture<List<E>> async() {

private class CallStream<E> implements HttpCall<Stream<E>> {
private final Class<E> type;
private final ParameterizedType genericType;
private final Type genericType;
private final boolean isGeneric;

CallStream(Class<E> type) {
Expand All @@ -333,7 +333,7 @@ private class CallStream<E> implements HttpCall<Stream<E>> {
this.genericType = null;
}

CallStream(ParameterizedType type) {
CallStream(Type type) {
this.isGeneric = true;
this.type = null;
this.genericType = type;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -270,7 +270,7 @@ default <E> CompletableFuture<HttpResponse<E>> withHandler(HttpResponse.BodyHand
/**
* The same as {@link #as(Class)} but using a generic type.
*/
<E> CompletableFuture<HttpResponse<E>> as(ParameterizedType type);
<E> CompletableFuture<HttpResponse<E>> as(Type type);

/**
* Process expecting a bean response body (typically from json content).
Expand Down Expand Up @@ -346,7 +346,7 @@ default <E> CompletableFuture<HttpResponse<E>> withHandler(HttpResponse.BodyHand
/**
* The same as {@link #asList(Class)} but using a generic type.
*/
<E> CompletableFuture<HttpResponse<List<E>>> asList(ParameterizedType type);
<E> CompletableFuture<HttpResponse<List<E>>> asList(Type type);

/**
* Process expecting a list of beans response body (typically from json content).
Expand Down Expand Up @@ -419,7 +419,7 @@ default <E> CompletableFuture<HttpResponse<E>> withHandler(HttpResponse.BodyHand
/**
* The same as {@link #asStream(Class)} but using a generic type.
*/
<E> CompletableFuture<HttpResponse<Stream<E>>> asStream(ParameterizedType type);
<E> CompletableFuture<HttpResponse<Stream<E>>> asStream(Type type);

/**
* Process response as a stream of beans (x-json-stream).
Expand Down Expand Up @@ -463,25 +463,25 @@ default <E> CompletableFuture<HttpResponse<E>> 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
*/
<E> CompletableFuture<E> bean(ParameterizedType type);
<E> CompletableFuture<E> 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
*/
<E> CompletableFuture<List<E>> list(ParameterizedType type);
<E> CompletableFuture<List<E>> 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
*/
<E> CompletableFuture<Stream<E>> stream(ParameterizedType type);
<E> CompletableFuture<Stream<E>> stream(Type type);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -150,7 +150,7 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
/**
* Same as {@link #as(Class)} but takes a generic parameterized type.
*/
<E> HttpCall<HttpResponse<E>> as(ParameterizedType type);
<E> HttpCall<HttpResponse<E>> as(Type type);

/**
* Same as {@link #as(Class)} but returns {@code HttpResponse<List<E>>}.
Expand All @@ -160,7 +160,7 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
/**
* Same as {@link #as(Class)} but returns {@code HttpResponse<List<E>>}.
*/
<E> HttpCall<HttpResponse<List<E>>> asList(ParameterizedType type);
<E> HttpCall<HttpResponse<List<E>>> asList(Type type);

/**
* Same as {@link #as(Class)} but returns {@code HttpResponse<Stream<E>>}.
Expand All @@ -170,7 +170,7 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
/**
* Same as {@link #as(Class)} but returns {@code HttpResponse<Stream<E>>}.
*/
<E> HttpCall<HttpResponse<Stream<E>>> asStream(ParameterizedType type);
<E> HttpCall<HttpResponse<Stream<E>>> asStream(Type type);

/**
* A bean response to execute async or sync.
Expand Down Expand Up @@ -239,22 +239,22 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
* @param type The parameterized type to convert the content to
* @return The HttpCall to allow sync or async execution
*/
<E> HttpCall<E> bean(ParameterizedType type);
<E> HttpCall<E> 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
* @return The HttpCall to execute sync or async
*/
<E> HttpCall<List<E>> list(ParameterizedType type);
<E> HttpCall<List<E>> list(Type type);

/**
* Process expecting a stream of beans response body (typically from json content).
*
* @param type The parameterized type to convert the content to
* @return The HttpCall to execute sync or async
*/
<E> HttpCall<Stream<E>> stream(ParameterizedType type);
<E> HttpCall<Stream<E>> stream(Type type);

}
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ default HttpClientRequest queryParam(String name, Collection<String> 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);
Expand Down
Loading