io.sphere.sdk.client.SphereRequestBase Maven / Gradle / Ivy
package io.sphere.sdk.client;
import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.http.HttpResponse;
import io.sphere.sdk.json.JsonException;
import io.sphere.sdk.json.SphereJsonUtils;
import io.sphere.sdk.models.Base;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
/**
* A base class with utility methods for the implementation of {@link io.sphere.sdk.client.SphereRequest}s.
*/
public abstract class SphereRequestBase extends Base {
//do not add field members here
protected SphereRequestBase() {
}
public static T deserialize(final HttpResponse httpResponse, final TypeReference typeReference) {
return SphereJsonUtils.readObject(Optional.ofNullable(httpResponse.getResponseBody()).orElseThrow(() -> new JsonException(httpResponse)), typeReference);
}
protected static String getBodyAsString(final HttpResponse httpResponse) {
return new String(httpResponse.getResponseBody(), StandardCharsets.UTF_8);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy