io.sphere.sdk.customobjects.queries.CustomObjectCustomJsonMappingByXGet Maven / Gradle / Ivy
package io.sphere.sdk.customobjects.queries;
import io.sphere.sdk.client.HttpRequestIntent;
import io.sphere.sdk.customobjects.CustomObject;
import io.sphere.sdk.http.HttpResponse;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.queries.Get;
import javax.annotation.Nullable;
import java.util.function.Function;
import static io.sphere.sdk.http.HttpMethod.GET;
import static io.sphere.sdk.http.HttpStatusCode.NOT_FOUND_404;
abstract class CustomObjectCustomJsonMappingByXGet extends Base implements Get> {
private final String path;
public CustomObjectCustomJsonMappingByXGet(final String path) {
this.path = path;
}
@Override
public HttpRequestIntent httpRequestIntent() {
return HttpRequestIntent.of(GET, CustomObjectEndpoint.PATH + path);
}
@Nullable
@Override
public final CustomObject deserialize(final HttpResponse httpResponse) {
return (httpResponse.getStatusCode() == NOT_FOUND_404) ? null : deserializeCustomObject(httpResponse);
}
protected abstract CustomObject deserializeCustomObject(final HttpResponse httpResponse);
@Override
public boolean canDeserialize(final HttpResponse httpResponse) {
return httpResponse.hasSuccessResponseCode() || httpResponse.getStatusCode() == NOT_FOUND_404;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy