Skip to content

Commit 208b58d

Browse files
authored
Merge pull request #194 from SentryMan/types
[http client] Use more generic Type rather than ParameterizedType
2 parents 5766c9c + 2584570 commit 208b58d

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

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

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

3-
import java.lang.reflect.ParameterizedType;
3+
import java.lang.reflect.Type;
44
import java.util.List;
55

66
/**
@@ -22,9 +22,9 @@ public interface BodyAdapter {
2222
*
2323
* @param type The type of the bean this writer is for
2424
*/
25-
default <T> BodyWriter<T> beanWriter(ParameterizedType type) {
25+
default <T> BodyWriter<T> beanWriter(Type type) {
2626

27-
throw new UnsupportedOperationException("Parameterized types not supported for this adapter");
27+
throw new UnsupportedOperationException("java.lang.reflect.Type is not supported for this adapter");
2828
}
2929

3030
/**
@@ -39,8 +39,8 @@ default <T> BodyWriter<T> beanWriter(ParameterizedType type) {
3939
*
4040
* @param type The bean type to convert the content to.
4141
*/
42-
default <T> BodyReader<T> beanReader(ParameterizedType type) {
43-
throw new UnsupportedOperationException("Parameterized types not supported for this adapter");
42+
default <T> BodyReader<T> beanReader(Type type) {
43+
throw new UnsupportedOperationException("java.lang.reflect.Type is not supported for this adapter");
4444
}
4545

4646
/**
@@ -55,7 +55,7 @@ default <T> BodyReader<T> beanReader(ParameterizedType type) {
5555
*
5656
* @param type The bean type to convert the content to.
5757
*/
58-
default <T> BodyReader<List<T>> listReader(ParameterizedType type) {
59-
throw new UnsupportedOperationException("Parameterized types not supported for this adapter");
58+
default <T> BodyReader<List<T>> listReader(Type type) {
59+
throw new UnsupportedOperationException("java.lang.reflect.Type is not supported for this adapter");
6060
}
6161
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.io.IOException;
44
import java.lang.reflect.Constructor;
5-
import java.lang.reflect.ParameterizedType;
5+
import java.lang.reflect.Type;
66
import java.net.http.HttpHeaders;
77
import java.net.http.HttpRequest;
88
import java.net.http.HttpResponse;
@@ -269,15 +269,15 @@ <T> BodyContent write(T bean, Class<?> type, String contentType) {
269269
return bodyAdapter.beanWriter(type).write(bean, contentType);
270270
}
271271

272-
<T> BodyContent write(T bean, ParameterizedType type, String contentType) {
272+
<T> BodyContent write(T bean, Type type, String contentType) {
273273
return bodyAdapter.beanWriter(type).write(bean, contentType);
274274
}
275275

276276
<T> BodyReader<T> beanReader(Class<T> type) {
277277
return bodyAdapter.beanReader(type);
278278
}
279279

280-
<T> BodyReader<T> beanReader(ParameterizedType type) {
280+
<T> BodyReader<T> beanReader(Type type) {
281281
return bodyAdapter.beanReader(type);
282282
}
283283

@@ -290,12 +290,12 @@ <T> List<T> readList(Class<T> type, BodyContent content) {
290290
}
291291

292292
@SuppressWarnings("unchecked")
293-
<T> T readBean(ParameterizedType type, BodyContent content) {
293+
<T> T readBean(Type type, BodyContent content) {
294294
return (T) bodyAdapter.beanReader(type).read(content);
295295
}
296296

297297
@SuppressWarnings("unchecked")
298-
<T> List<T> readList(ParameterizedType type, BodyContent content) {
298+
<T> List<T> readList(Type type, BodyContent content) {
299299
return (List<T>) bodyAdapter.listReader(type).read(content);
300300
}
301301

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javax.net.ssl.SSLSession;
44
import java.io.FileNotFoundException;
55
import java.io.InputStream;
6-
import java.lang.reflect.ParameterizedType;
6+
import java.lang.reflect.Type;
77
import java.net.URI;
88
import java.net.URLEncoder;
99
import java.net.http.HttpClient;
@@ -282,7 +282,7 @@ public HttpClientRequest body(Object bean, Class<?> type) {
282282
}
283283

284284
@Override
285-
public HttpClientRequest body(Object bean, ParameterizedType type) {
285+
public HttpClientRequest body(Object bean, Type type) {
286286
encodedRequestBody = context.write(bean, type, null);
287287
return this;
288288
}
@@ -465,7 +465,7 @@ public <T> HttpResponse<T> as(Class<T> type) {
465465
}
466466

467467
@Override
468-
public <T> HttpResponse<T> as(ParameterizedType type) {
468+
public <T> HttpResponse<T> as(Type type) {
469469
return new HttpWrapperResponse<>(bean(type), httpResponse);
470470
}
471471

@@ -476,7 +476,7 @@ public <T> T bean(Class<T> type) {
476476
}
477477

478478
@Override
479-
public <T> T bean(ParameterizedType type) {
479+
public <T> T bean(Type type) {
480480
readResponseContent();
481481
return context.readBean(type, encodedResponseBody);
482482
}
@@ -487,7 +487,7 @@ public <T> HttpResponse<List<T>> asList(Class<T> type) {
487487
}
488488

489489
@Override
490-
public <T> HttpResponse<List<T>> asList(ParameterizedType type) {
490+
public <T> HttpResponse<List<T>> asList(Type type) {
491491
return new HttpWrapperResponse<>(list(type), httpResponse);
492492
}
493493

@@ -498,7 +498,7 @@ public <T> List<T> list(Class<T> type) {
498498
}
499499

500500
@Override
501-
public <T> List<T> list(ParameterizedType type) {
501+
public <T> List<T> list(Type type) {
502502
readResponseContent();
503503
return context.readList(type, encodedResponseBody);
504504
}
@@ -509,7 +509,7 @@ public <T> HttpResponse<Stream<T>> asStream(Class<T> type) {
509509
}
510510

511511
@Override
512-
public <T> HttpResponse<Stream<T>> asStream(ParameterizedType type) {
512+
public <T> HttpResponse<Stream<T>> asStream(Type type) {
513513
return new HttpWrapperResponse<>(stream(type), httpResponse);
514514
}
515515

@@ -519,7 +519,7 @@ public <T> Stream<T> stream(Class<T> type) {
519519
}
520520

521521
@Override
522-
public <T> Stream<T> stream(ParameterizedType type) {
522+
public <T> Stream<T> stream(Type type) {
523523
return stream(context.beanReader(type));
524524
}
525525

@@ -577,7 +577,7 @@ protected <E> HttpResponse<E> asyncBean(Class<E> type, HttpResponse<byte[]> resp
577577
return new HttpWrapperResponse<>(context.readBean(type, encodedResponseBody), httpResponse);
578578
}
579579

580-
protected <E> E asyncBean(ParameterizedType type, HttpResponse<byte[]> response) {
580+
protected <E> E asyncBean(Type type, HttpResponse<byte[]> response) {
581581
afterAsyncEncoded(response);
582582
return context.readBean(type, encodedResponseBody);
583583
}
@@ -587,7 +587,7 @@ protected <E> HttpResponse<List<E>> asyncList(Class<E> type, HttpResponse<byte[]
587587
return new HttpWrapperResponse<>(context.readList(type, encodedResponseBody), httpResponse);
588588
}
589589

590-
protected <E> HttpResponse<List<E>> asyncList(ParameterizedType type, HttpResponse<byte[]> response) {
590+
protected <E> HttpResponse<List<E>> asyncList(Type type, HttpResponse<byte[]> response) {
591591
afterAsyncEncoded(response);
592592
return new HttpWrapperResponse<>(context.readList(type, encodedResponseBody), httpResponse);
593593
}
@@ -603,7 +603,7 @@ protected <E> HttpResponse<Stream<E>> asyncStream(Class<E> type, HttpResponse<St
603603
return new HttpWrapperResponse<>(response.body().map(bodyReader::readBody), httpResponse);
604604
}
605605

606-
protected <E> HttpResponse<Stream<E>> asyncStream(ParameterizedType type, HttpResponse<Stream<String>> response) {
606+
protected <E> HttpResponse<Stream<E>> asyncStream(Type type, HttpResponse<Stream<String>> response) {
607607
responseTimeNanos = System.nanoTime() - startAsyncNanos;
608608
httpResponse = response;
609609
context.afterResponse(this);

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

Lines changed: 2 additions & 2 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.HttpRequest;
66
import java.net.http.HttpResponse;
77
import java.nio.file.Path;
@@ -324,7 +324,7 @@ default HttpClientRequest queryParam(String name, Collection<String> values) {
324324
* @param type The parameterized type used by the body content adapter to write the body content
325325
* @return The request being built
326326
*/
327-
HttpClientRequest body(Object bean, ParameterizedType type);
327+
HttpClientRequest body(Object bean, Type type);
328328

329329
/**
330330
* Set the body as a bean with the given content type and additionally specifying

http-client/src/main/java/io/avaje/http/client/HttpClientResponse.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.nio.file.Path;
77
import java.util.List;
@@ -83,7 +83,7 @@ public interface HttpClientResponse {
8383
* @return The response containing the converted body.
8484
* @throws HttpException when the response has error status codes
8585
*/
86-
<T> HttpResponse<T> as(ParameterizedType type);
86+
<T> HttpResponse<T> as(Type type);
8787

8888
/**
8989
* Return the response with the body containing a list of the given type.
@@ -109,7 +109,7 @@ public interface HttpClientResponse {
109109
* @return The response containing the converted body.
110110
* @throws HttpException when the response has error status codes
111111
*/
112-
<T> HttpResponse<List<T>> asList(ParameterizedType type);
112+
<T> HttpResponse<List<T>> asList(Type type);
113113

114114
/**
115115
* Return the response with the body containing a stream of beans of the given type.
@@ -151,7 +151,7 @@ public interface HttpClientResponse {
151151
* @return The response containing the converted body.
152152
* @throws HttpException when the response has error status codes
153153
*/
154-
<T> HttpResponse<Stream<T>> asStream(ParameterizedType type);
154+
<T> HttpResponse<Stream<T>> asStream(Type type);
155155

156156
/**
157157
* Return the response as a single bean.
@@ -210,7 +210,7 @@ public interface HttpClientResponse {
210210
* @return The bean the response is converted into.
211211
* @throws HttpException when the response has error status codes
212212
*/
213-
<T> T bean(ParameterizedType type);
213+
<T> T bean(Type type);
214214

215215
/**
216216
* Return the response as a list of beans.
@@ -222,7 +222,7 @@ public interface HttpClientResponse {
222222
* @return The list of beans the response is converted into.
223223
* @throws HttpException when the response has error status codes
224224
*/
225-
<T> List<T> list(ParameterizedType type);
225+
<T> List<T> list(Type type);
226226

227227
/**
228228
* Return the response as a stream of beans.
@@ -242,7 +242,7 @@ public interface HttpClientResponse {
242242
* @return The stream of beans from the response
243243
* @throws HttpException when the response has error status codes
244244
*/
245-
<T> Stream<T> stream(ParameterizedType type);
245+
<T> Stream<T> stream(Type type);
246246

247247
/**
248248
* Return the response with check for 200 range status code.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public HttpException(int statusCode, Throwable cause) {
7575
}
7676

7777
HttpException(HttpResponse<?> httpResponse, DHttpClientContext context) {
78-
super();
78+
super("Http Call failed with status: " + httpResponse.statusCode());
7979
this.httpResponse = httpResponse;
8080
this.statusCode = httpResponse.statusCode();
8181
this.context = context;
8282
this.responseAsBytes = false;
8383
}
8484

8585
HttpException(DHttpClientContext context, HttpResponse<byte[]> httpResponse) {
86-
super();
86+
super("Http Call failed with status: " + httpResponse.statusCode());
8787
this.httpResponse = httpResponse;
8888
this.statusCode = httpResponse.statusCode();
8989
this.context = context;

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

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

3-
import java.lang.reflect.ParameterizedType;
43
import java.lang.reflect.Type;
54
import java.util.List;
65
import java.util.concurrent.ConcurrentHashMap;
@@ -49,7 +48,7 @@ public <T> BodyWriter<T> beanWriter(Class<?> cls) {
4948

5049
@SuppressWarnings("unchecked")
5150
@Override
52-
public <T> BodyWriter<T> beanWriter(ParameterizedType type) {
51+
public <T> BodyWriter<T> beanWriter(Type type) {
5352
return (BodyWriter<T>) beanWriterCache.computeIfAbsent(type, aClass -> new JWriter<>(jsonb.type(type)));
5453
}
5554

@@ -61,13 +60,13 @@ public <T> BodyReader<T> beanReader(Class<T> cls) {
6160

6261
@SuppressWarnings("unchecked")
6362
@Override
64-
public <T> BodyReader<T> beanReader(ParameterizedType type) {
63+
public <T> BodyReader<T> beanReader(Type type) {
6564
return (BodyReader<T>) beanReaderCache.computeIfAbsent(type, aClass -> new JReader<>(jsonb.type(type)));
6665
}
6766

6867
@SuppressWarnings("unchecked")
6968
@Override
70-
public <T> BodyReader<List<T>> listReader(ParameterizedType type) {
69+
public <T> BodyReader<List<T>> listReader(Type type) {
7170
return (BodyReader<List<T>>) listReaderCache.computeIfAbsent(type, aClass -> new JReader<>(jsonb.type(type).list()));
7271
}
7372

0 commit comments

Comments
 (0)