@Override public HttpRequestIntent httpRequestIntent() { return delegate.httpRequestIntent(); }
@Override public boolean canDeserialize(final HttpResponse httpResponse) { return delegate.canDeserialize(httpResponse); } }
@Override public T deserialize(final HttpResponse httpResponse) { return delegate.deserialize(httpResponse); } }
static <T> T parse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) { final T result; if (!sphereRequest.canDeserialize(httpResponse)) { final SphereException sphereException = createExceptionFor(httpResponse, sphereRequest, objectMapper, config, httpRequest); throw sphereException; } else { try { result = sphereRequest.deserialize(httpResponse); } catch (final JsonException e) { final byte[] bytes = httpResponse.getResponseBody(); e.addNote("Cannot parse " + bytesToString(bytes)); throw e; } } return result; }
static <T> T parse(final HttpResponse httpResponse, final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config) { final T result; if (!sphereRequest.canHandleResponse(httpResponse)) { final SphereException sphereException = createExceptionFor(httpResponse, sphereRequest, objectMapper, config); throw sphereException; } else { try { result = sphereRequest.resultMapper().apply(httpResponse); } catch (final JsonException e) { final byte[] bytes = httpResponse.getResponseBody().get(); throw new JsonException("Cannot parse " + bytesToString(bytes), e); } } return result; }
@Override public Function<HttpResponse, T> resultMapper() { return delegate.resultMapper(); } }
@Override public boolean canHandleResponse(final HttpResponse response) { return delegate.canHandleResponse(response); }
static <T> T parse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse) { final T result; if (!sphereRequest.canDeserialize(httpResponse)) { final SphereException sphereException = createExceptionFor(httpResponse, sphereRequest, objectMapper, config); throw sphereException; } else { try { result = sphereRequest.deserialize(httpResponse); } catch (final JsonException e) { final byte[] bytes = httpResponse.getResponseBody(); e.addNote("Cannot parse " + bytesToString(bytes)); throw e; } } return result; }
@Override public Function<HttpResponse, T> resultMapper() { return response -> { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(response); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.resultMapper().apply(response); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(response); throw sphereException; } }; }
@Override public boolean canHandleResponse(final HttpResponse response) { return !getDeprecationNoticeHeaderValues(response).isEmpty() || sphereRequest.canHandleResponse(response); }
@Override public HttpRequestIntent httpRequestIntent() { return sphereRequest.httpRequestIntent(); }
static <T> T parse(final SphereRequest<T> sphereRequest, final ObjectMapper objectMapper, final SphereApiConfig config, final HttpResponse httpResponse, final HttpRequest httpRequest) { final T result; if (!sphereRequest.canDeserialize(httpResponse)) { final SphereException sphereException = createExceptionFor(httpResponse, sphereRequest, objectMapper, config, httpRequest); throw sphereException; } else { try { result = sphereRequest.deserialize(httpResponse); } catch (final JsonException e) { final byte[] bytes = httpResponse.getResponseBody(); e.addNote("Cannot parse " + bytesToString(bytes)); throw e; } } return result; }
@Nullable @Override public Pair<T, HttpResponse> deserialize(final HttpResponse httpResponse) { final T javaObject = delegate.deserialize(httpResponse); return ImmutablePair.of(javaObject, httpResponse); }
@Override public boolean canDeserialize(final HttpResponse httpResponse) { return delegate.canDeserialize(httpResponse); } }
@Override public HttpRequestIntent httpRequestIntent() { return sphereRequest.httpRequestIntent(); }
@Nullable @Override public Pair<T, JsonNode> deserialize(final HttpResponse httpResponse) { final JsonNode jsonNode = JsonNodeSphereRequest.of(delegate).deserialize(httpResponse); final T javaObject = delegate.deserialize(httpResponse); return ImmutablePair.of(javaObject, jsonNode); }
@Override public boolean canDeserialize(final HttpResponse httpResponse) { return delegate.canDeserialize(httpResponse); }
@Override public HttpRequestIntent httpRequestIntent() { return delegate.httpRequestIntent(); }
@Override public T deserialize(final HttpResponse httpResponse) { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(httpResponse); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.deserialize(httpResponse); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(httpResponse); throw sphereException; } }
@Override public boolean canDeserialize(final HttpResponse httpResponse) { return !getDeprecationNoticeHeaderValues(httpResponse).isEmpty() || sphereRequest.canDeserialize(httpResponse); }