T
- the Java class of the originals SphereRequest
s result.public final class JavaAndJsonSphereRequest<T> extends Base implements SphereRequest<org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode>>
SphereRequest
to receive the Java object as well as the JsonNode
representation.
withCategory(client(), category -> { final CategoryByIdGet originalRequest = CategoryByIdGet.of(category); final JavaAndJsonSphereRequest<Category> request = JavaAndJsonSphereRequest.of(originalRequest); final Pair<Category, JsonNode> result = client().executeBlocking(request); final Category categoryJavaObject = result.getLeft(); final JsonNode categoryAsJson = result.getRight(); assertThat(categoryJavaObject).isEqualTo(category); assertThat(categoryAsJson.get("id").asText()).isEqualTo(category.getId()); });
See the test code.
Modifier and Type | Method and Description |
---|---|
boolean |
canDeserialize(HttpResponse httpResponse)
Checks if the response can be handled by
SphereRequest.deserialize(HttpResponse) . |
org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode> |
deserialize(HttpResponse httpResponse)
Takes an http response and maps it into a Java object of type T.
|
HttpRequestIntent |
httpRequestIntent()
Provides an http request intent, this does not include the execution of it.
|
static <T> JavaAndJsonSphereRequest<T> |
of(SphereRequest<T> delegate) |
public static <T> JavaAndJsonSphereRequest<T> of(SphereRequest<T> delegate)
@Nullable public org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode> deserialize(HttpResponse httpResponse)
SphereRequest
SphereRequest.canDeserialize(HttpResponse)
if the response can be consumed.deserialize
in interface SphereRequest<org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode>>
httpResponse
- the http response of the APIpublic HttpRequestIntent httpRequestIntent()
SphereRequest
httpRequestIntent
in interface SphereRequest<org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode>>
public boolean canDeserialize(HttpResponse httpResponse)
SphereRequest
SphereRequest.deserialize(HttpResponse)
.
Use case 1: A http response returns 404 and the this SphereRequest
can handle this error by returning an empty optional, an empty list or throwing a domain specific exception.canDeserialize
in interface SphereRequest<org.apache.commons.lang3.tuple.Pair<T,com.fasterxml.jackson.databind.JsonNode>>
httpResponse
- the http response which shall be transformed