use of co.elastic.clients.json.JsonpDeserializer in project elasticsearch-java by elastic.
the class RestClientTransport method decodeResponse.
private <ResponseT> ResponseT decodeResponse(int statusCode, @Nullable HttpEntity entity, Response clientResp, Endpoint<?, ResponseT, ?> endpoint) throws IOException {
if (endpoint instanceof BooleanEndpoint) {
BooleanEndpoint<?> bep = (BooleanEndpoint<?>) endpoint;
@SuppressWarnings("unchecked") ResponseT response = (ResponseT) new BooleanResponse(bep.getResult(statusCode));
return response;
} else if (endpoint instanceof JsonEndpoint) {
@SuppressWarnings("unchecked") JsonEndpoint<?, ResponseT, ?> jsonEndpoint = (JsonEndpoint<?, ResponseT, ?>) endpoint;
// Successful response
ResponseT response = null;
JsonpDeserializer<ResponseT> responseParser = jsonEndpoint.responseDeserializer();
if (responseParser != null) {
// Expecting a body
if (entity == null) {
throw new TransportException("Expecting a response body, but none was sent", endpoint.id(), new ResponseException(clientResp));
}
InputStream content = entity.getContent();
try (JsonParser parser = mapper.jsonProvider().createParser(content)) {
response = responseParser.deserialize(parser, mapper);
}
;
}
return response;
} else {
throw new TransportException("Unhandled endpoint type: '" + endpoint.getClass().getName() + "'", endpoint.id());
}
}
Aggregations