All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.requests.FetchImpl Maven / Gradle / Ivy

package io.sphere.sdk.requests;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Function;
import java.util.Optional;
import io.sphere.sdk.utils.JsonUtils;

public abstract class FetchImpl implements Fetch {
    @Override
    public Function> resultMapper() {
        return httpResponse -> {
            final Optional result;
            if (httpResponse.getStatusCode() == 404) {
                result = Optional.empty();
            } else {
                result = Optional.of(JsonUtils.readObjectFromJsonString(typeReference(), httpResponse.getResponseBody()));
            }
            return result;
        };
    }

    protected abstract TypeReference typeReference();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy