Skip to content

Commit 0d06b7d

Browse files
authored
Merge pull request #54 from polyapi/develop
Develop
2 parents 82b7c62 + 704cf11 commit 0d06b7d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,4 @@ Comparing to its Typescript counterpart, the Java library is still missing the f
360360
These features will be added in the future releases.
361361

362362
## Changelog
363-
See the Changelog **[here](https://github.com/polyapi/polyapi-java/releases)**.
363+
See the Changelog **[here](https://github.com/polyapi/polyapi-java/releases)**.

commons/src/main/java/io/polyapi/commons/api/service/PolyApiService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ private <I, O> O parsedCall(HttpMethod method, String relativePath, Map<String,
9393
if (contentType.startsWith("application/json")) {
9494
parsedResult = jsonParser.parseInputStream(response.body(), TypeVariable.class.isAssignableFrom(type.getClass()) ? Object.class : type);
9595
} else {
96-
if ((type.getClass().isAssignableFrom(String.class) || TypeVariable.class.isAssignableFrom(type.getClass())) && contentType.startsWith("text/")) {
96+
if (checkType(type, String.class) && contentType.startsWith("text/")) {
9797
try {
9898
parsedResult = (O)IOUtils.toString(response.body(), defaultCharset());
9999
} catch (IOException e) {
100100
throw new ParsingException("An error occurred while parsing the response.", e);
101101
}
102102
} else {
103-
if ((InputStream.class.isAssignableFrom(type.getClass()) || type.getClass().isAssignableFrom(TypeVariable.class))) {
103+
if (checkType(type, InputStream.class)) {
104104
parsedResult = (O)response.body();
105105
} else {
106106
throw new UnsupportedContentTypeException(contentType, type);
@@ -114,6 +114,10 @@ private <I, O> O parsedCall(HttpMethod method, String relativePath, Map<String,
114114
return result;
115115
}
116116

117+
private boolean checkType(Type type, Class<?> expectedClass) {
118+
return (type.getClass().isAssignableFrom(Class.class) && Class.class.cast(type).isAssignableFrom(expectedClass)) || TypeVariable.class.isAssignableFrom(type.getClass());
119+
}
120+
117121
private Response callApi(HttpMethod method, String relativePath, Map<String, List<String>> headers, Map<String, List<String>> queryParams, InputStream body) {
118122
Request request = client.prepareAuthenticatedRequest(host, port, method, relativePath)
119123
.withHeaders(headers)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@
244244
</distributionManagement>
245245
</profile>
246246
</profiles>
247-
</project>
247+
</project>

0 commit comments

Comments
 (0)