io.sphere.sdk.customobjects.queries.CustomObjectByIdGetImpl Maven / Gradle / Ivy
package io.sphere.sdk.customobjects.queries;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import io.sphere.sdk.client.JsonEndpoint;
import io.sphere.sdk.customobjects.CustomObject;
import io.sphere.sdk.customobjects.expansion.CustomObjectExpansionModel;
import io.sphere.sdk.http.HttpResponse;
import io.sphere.sdk.json.SphereJsonUtils;
import io.sphere.sdk.queries.MetaModelGetDslBuilder;
import io.sphere.sdk.queries.MetaModelGetDslImpl;
import java.util.Optional;
final class CustomObjectByIdGetImpl extends MetaModelGetDslImpl, CustomObject, CustomObjectByIdGet, CustomObjectExpansionModel>> implements CustomObjectByIdGet {
private final JavaType customObjectJavaType;
CustomObjectByIdGetImpl(final String id, final JavaType javaType) {
super(id, JsonEndpoint.of(new TypeReference>() {
@Override
public String toString() {
return "TypeReference>";
}
}, "/custom-objects"), CustomObjectExpansionModel.of(), att -> new CustomObjectByIdGetImpl(att, javaType));
this.customObjectJavaType = SphereJsonUtils.createCustomObjectJavaType(CustomObject.class, javaType.getRawClass());
}
CustomObjectByIdGetImpl(final MetaModelGetDslBuilder, CustomObject, CustomObjectByIdGet, CustomObjectExpansionModel>> builder, JavaType javaType){
super(builder);
this.customObjectJavaType = SphereJsonUtils.createCustomObjectJavaType(CustomObject.class, javaType.getRawClass());
}
@Override
public CustomObject deserialize(final HttpResponse httpResponse) {
return deserializeCustomObject(httpResponse);
}
protected CustomObject deserializeCustomObject(final HttpResponse httpResponse) {
if(!httpResponse.hasSuccessResponseCode()){
return null;
}
return Optional.ofNullable(httpResponse)
.filter(response -> response.getResponseBody() != null && response.getResponseBody().length > 0)
.map(response -> response.getResponseBody())
.map(responseBody -> SphereJsonUtils.>readObject(httpResponse.getResponseBody(), customObjectJavaType))
.orElse(null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy