Skip to content

Commit 97f4d3c

Browse files
authored
Merge pull request #199 from SentryMan/types
[http client] Change Async API to use more generic Type instead of ParameterizedType
2 parents 5da5ea8 + 42841de commit 97f4d3c

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

http-client/src/main/java/io/avaje/http/client/DHttpAsync.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
import java.io.InputStream;
4-
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
55
import java.net.http.HttpResponse;
66
import java.util.List;
77
import java.util.concurrent.CompletableFuture;
@@ -65,7 +65,7 @@ public <E> CompletableFuture<E> bean(Class<E> type) {
6565
}
6666

6767
@Override
68-
public <E> CompletableFuture<E> bean(ParameterizedType type) {
68+
public <E> CompletableFuture<E> bean(Type type) {
6969
final CompletableFuture<HttpResponse<E>> future = as(type);
7070
return future.thenApply(HttpResponse::body);
7171
}
@@ -76,7 +76,7 @@ public <E> CompletableFuture<HttpResponse<E>> as(Class<E> type) {
7676
}
7777

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

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

8888
@Override
89-
public <E> CompletableFuture<List<E>> list(ParameterizedType type) {
89+
public <E> CompletableFuture<List<E>> list(Type type) {
9090
final CompletableFuture<HttpResponse<List<E>>> future = asList(type);
9191
return future.thenApply(HttpResponse::body);
9292
}
@@ -97,7 +97,7 @@ public <E> CompletableFuture<HttpResponse<List<E>>> asList(Class<E> type) {
9797
}
9898

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

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

109109
@Override
110-
public <E> CompletableFuture<Stream<E>> stream(ParameterizedType type) {
110+
public <E> CompletableFuture<Stream<E>> stream(Type type) {
111111
final CompletableFuture<HttpResponse<Stream<E>>> future = asStream(type);
112112
return future.thenApply(HttpResponse::body);
113113
}
@@ -118,7 +118,7 @@ public <E> CompletableFuture<HttpResponse<Stream<E>>> asStream(Class<E> type) {
118118
}
119119

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

http-client/src/main/java/io/avaje/http/client/DHttpCall.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
import java.io.InputStream;
4-
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
55
import java.net.http.HttpResponse;
66
import java.util.List;
77
import java.util.concurrent.CompletableFuture;
@@ -61,7 +61,7 @@ public <E> HttpCall<HttpResponse<E>> as(Class<E> type) {
6161
}
6262

6363
@Override
64-
public <E> HttpCall<HttpResponse<E>> as(ParameterizedType type) {
64+
public <E> HttpCall<HttpResponse<E>> as(Type type) {
6565
return new CallAs<>(type);
6666
}
6767

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

7373
@Override
74-
public <E> HttpCall<HttpResponse<List<E>>> asList(ParameterizedType type) {
74+
public <E> HttpCall<HttpResponse<List<E>>> asList(Type type) {
7575
return new CallAsList<>(type);
7676
}
7777

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

8383
@Override
84-
public <E> HttpCall<HttpResponse<Stream<E>>> asStream(ParameterizedType type) {
84+
public <E> HttpCall<HttpResponse<Stream<E>>> asStream(Type type) {
8585
return new CallAsStream<>(type);
8686
}
8787

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

9898
@Override
99-
public <E> HttpCall<E> bean(ParameterizedType type) {
99+
public <E> HttpCall<E> bean(Type type) {
100100
return new CallBean<>(type);
101101
}
102102

103103
@Override
104-
public <E> HttpCall<List<E>> list(ParameterizedType type) {
104+
public <E> HttpCall<List<E>> list(Type type) {
105105
return new CallList<>(type);
106106
}
107107

108108
@Override
109-
public <E> HttpCall<Stream<E>> stream(ParameterizedType type) {
109+
public <E> HttpCall<Stream<E>> stream(Type type) {
110110
return new CallStream<>(type);
111111
}
112112

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

185185
private class CallAs<E> implements HttpCall<HttpResponse<E>> {
186186
private final Class<E> type;
187-
private final ParameterizedType genericType;
187+
private final Type genericType;
188188
private final boolean isGeneric;
189189

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

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

213213
private class CallAsList<E> implements HttpCall<HttpResponse<List<E>>> {
214214
private final Class<E> type;
215-
private final ParameterizedType genericType;
215+
private final Type genericType;
216216
private final boolean isGeneric;
217217

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

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

241241
private class CallAsStream<E> implements HttpCall<HttpResponse<Stream<E>>> {
242242
private final Class<E> type;
243-
private final ParameterizedType genericType;
243+
private final Type genericType;
244244
private final boolean isGeneric;
245245

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

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

269269
private class CallBean<E> implements HttpCall<E> {
270270
private final Class<E> type;
271-
private final ParameterizedType genericType;
271+
private final Type genericType;
272272
private final boolean isGeneric;
273273

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

280-
CallBean(ParameterizedType type) {
280+
CallBean(Type type) {
281281
this.isGeneric = true;
282282
this.type = null;
283283
this.genericType = type;
@@ -296,7 +296,7 @@ public CompletableFuture<E> async() {
296296

297297
private class CallList<E> implements HttpCall<List<E>> {
298298
private final Class<E> type;
299-
private final ParameterizedType genericType;
299+
private final Type genericType;
300300
private final boolean isGeneric;
301301

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

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

325325
private class CallStream<E> implements HttpCall<Stream<E>> {
326326
private final Class<E> type;
327-
private final ParameterizedType genericType;
327+
private final Type genericType;
328328
private final boolean isGeneric;
329329

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

336-
CallStream(ParameterizedType type) {
336+
CallStream(Type type) {
337337
this.isGeneric = true;
338338
this.type = null;
339339
this.genericType = type;

http-client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
import java.io.InputStream;
4-
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
55
import java.net.http.HttpResponse;
66
import java.util.List;
77
import java.util.concurrent.CompletableFuture;
@@ -270,7 +270,7 @@ default <E> CompletableFuture<HttpResponse<E>> withHandler(HttpResponse.BodyHand
270270
/**
271271
* The same as {@link #as(Class)} but using a generic type.
272272
*/
273-
<E> CompletableFuture<HttpResponse<E>> as(ParameterizedType type);
273+
<E> CompletableFuture<HttpResponse<E>> as(Type type);
274274

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

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

424424
/**
425425
* Process response as a stream of beans (x-json-stream).
@@ -463,25 +463,25 @@ default <E> CompletableFuture<HttpResponse<E>> withHandler(HttpResponse.BodyHand
463463
/**
464464
* Process expecting a bean response body (typically from json content).
465465
*
466-
* @param type The parameterized type to convert the content to
466+
* @param type The type to convert the content to
467467
* @return The CompletableFuture of the response
468468
*/
469-
<E> CompletableFuture<E> bean(ParameterizedType type);
469+
<E> CompletableFuture<E> bean(Type type);
470470

471471
/**
472472
* Process expecting a list of beans response body (typically from json content).
473473
*
474-
* @param type The parameterized type to convert the content to
474+
* @param type The type to convert the content to
475475
* @return The CompletableFuture of the response
476476
*/
477-
<E> CompletableFuture<List<E>> list(ParameterizedType type);
477+
<E> CompletableFuture<List<E>> list(Type type);
478478

479479
/**
480480
* Process response as a stream of beans (x-json-stream).
481481
*
482-
* @param type The parameterized type to convert the content to
482+
* @param type The type to convert the content to
483483
* @return The CompletableFuture of the response
484484
*/
485-
<E> CompletableFuture<Stream<E>> stream(ParameterizedType type);
485+
<E> CompletableFuture<Stream<E>> stream(Type type);
486486

487487
}

http-client/src/main/java/io/avaje/http/client/HttpCallResponse.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.avaje.http.client;
22

33
import java.io.InputStream;
4-
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
55
import java.net.http.HttpResponse;
66
import java.util.List;
77
import java.util.stream.Stream;
@@ -150,7 +150,7 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
150150
/**
151151
* Same as {@link #as(Class)} but takes a generic parameterized type.
152152
*/
153-
<E> HttpCall<HttpResponse<E>> as(ParameterizedType type);
153+
<E> HttpCall<HttpResponse<E>> as(Type type);
154154

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

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

175175
/**
176176
* A bean response to execute async or sync.
@@ -239,22 +239,22 @@ default <E> HttpCall<HttpResponse<E>> withHandler(HttpResponse.BodyHandler<E> bo
239239
* @param type The parameterized type to convert the content to
240240
* @return The HttpCall to allow sync or async execution
241241
*/
242-
<E> HttpCall<E> bean(ParameterizedType type);
242+
<E> HttpCall<E> bean(Type type);
243243

244244
/**
245245
* Process expecting a list of beans response body (typically from json content).
246246
*
247247
* @param type The parameterized type to convert the content to
248248
* @return The HttpCall to execute sync or async
249249
*/
250-
<E> HttpCall<List<E>> list(ParameterizedType type);
250+
<E> HttpCall<List<E>> list(Type type);
251251

252252
/**
253253
* Process expecting a stream of beans response body (typically from json content).
254254
*
255255
* @param type The parameterized type to convert the content to
256256
* @return The HttpCall to execute sync or async
257257
*/
258-
<E> HttpCall<Stream<E>> stream(ParameterizedType type);
258+
<E> HttpCall<Stream<E>> stream(Type type);
259259

260260
}

http-client/src/main/java/io/avaje/http/client/HttpClientRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ default HttpClientRequest queryParam(String name, Collection<String> values) {
321321
* a type that is known to JsonbAdapter / the body content adapter used.
322322
*
323323
* @param bean The body content as an instance
324-
* @param type The parameterized type used by the body content adapter to write the body content
324+
* @param type The type used by the body content adapter to write the body content
325325
* @return The request being built
326326
*/
327327
HttpClientRequest body(Object bean, Type type);

0 commit comments

Comments
 (0)