use of com.github.ljtfreitas.julian.http.HTTPHeader.CONTENT_TYPE in project julian-http-client by ljtfreitas.
the class DefaultHTTPRequestIO method deserialize.
private Optional<CompletableFuture<T>> deserialize(HTTPClientResponse response) {
MediaType mediaType = response.headers().select(CONTENT_TYPE).map(h -> MediaType.valueOf(h.value())).orElseGet(MediaType::wildcard);
HTTPResponseReader<?> reader = codecs.readers().select(mediaType, source.returnType()).orElseThrow(() -> new HTTPResponseReaderException(format("There is no a HTTPResponseReader able to convert {0} to {1}", mediaType, source.returnType())));
return reader.read(response.body(), source.returnType()).map(c -> c.handleAsync(this::handle).toCompletableFuture());
}
Aggregations