T
- The type of the value of the custom object.public interface CustomObjectByIdGet<T> extends MetaModelGetDsl<CustomObject<T>,CustomObject<T>,CustomObjectByIdGet<T>,CustomObjectExpansionModel<CustomObject<T>>>
SphereRequest
to fetch one CustomObject
by id.
withCustomObject(client(), existingCustomObject -> {
final String id = existingCustomObject.getId();
final CustomObjectByIdGet<Foo> fetch =
CustomObjectByIdGet.of(id, Foo.class);
final CustomObject<Foo> customObject = client().executeBlocking(fetch);
assertThat(customObject).isEqualTo(existingCustomObject);
});
See the test code.
CustomObject
Modifier and Type | Method and Description |
---|---|
List<ExpansionPath<CustomObject<T>>> |
expansionPaths() |
static <T> CustomObjectByIdGet<T> |
of(String id,
Class<T> valueClass)
Creates an object to fetch a custom object by id with POJO mapping.
|
static <T> CustomObjectByIdGet<T> |
of(String id,
com.fasterxml.jackson.core.type.TypeReference<T> valueTypeReference)
Creates an object to fetch a custom object by the container and key with POJO mapping.
|
static CustomObjectByIdGet<com.fasterxml.jackson.databind.JsonNode> |
ofJsonNode(String id)
Creates an object to fetch a custom object by the container and get the result as
JsonNode . |
CustomObjectByIdGet<T> |
plusExpansionPaths(ExpansionPath<CustomObject<T>> expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
CustomObjectByIdGet<T> |
withExpansionPaths(ExpansionPath<CustomObject<T>> expansionPath)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath . |
CustomObjectByIdGet<T> |
withExpansionPaths(List<ExpansionPath<CustomObject<T>>> expansionPaths)
Creates a new object with the properties of the old object but replaces all expansion paths with
expansionPaths . |
deserialize
canDeserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths
static <T> CustomObjectByIdGet<T> of(String id, Class<T> valueClass)
T
- the type of the value in the custom objectid
- id of the custom object to fetchvalueClass
- the class of the value, if it not uses generics like lists, typically for POJOsstatic <T> CustomObjectByIdGet<T> of(String id, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeReference)
T
- the type of the value in the custom objectid
- id of the custom object to fetchvalueTypeReference
- the type reference of the value of the custom objectstatic CustomObjectByIdGet<com.fasterxml.jackson.databind.JsonNode> ofJsonNode(String id)
JsonNode
.id
- id of the custom object to fetchList<ExpansionPath<CustomObject<T>>> expansionPaths()
expansionPaths
in interface ExpansionPathContainer<CustomObject<T>>
expansionPaths
in interface ReferenceExpansionSupport<CustomObject<T>>
CustomObjectByIdGet<T> plusExpansionPaths(ExpansionPath<CustomObject<T>> expansionPath)
ReferenceExpansionDsl
expansionPath
to the expansion paths.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT);
assertThat(fetch.expansionPaths()).isEmpty();
final ProductProjectionByIdGet fetch2 =
fetch.plusExpansionPaths(ProductProjectionExpansionModel.of().categories());
assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged").isEmpty();
assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("categories[*]")));
assertThat(fetch2).isNotSameAs(fetch);
See the test code.
plusExpansionPaths
in interface ReferenceExpansionDsl<CustomObject<T>,CustomObjectByIdGet<T>>
expansionPath
- the new expansion path to add to the existing onesCustomObjectByIdGet<T> withExpansionPaths(ExpansionPath<CustomObject<T>> expansionPath)
ReferenceExpansionDsl
expansionPath
.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT)
.withExpansionPaths(ProductProjectionExpansionModel.of().categories());
assertThat(fetch.expansionPaths())
.isEqualTo(asList(ExpansionPath.of("categories[*]")));
final ProductProjectionByIdGet fetch2 =
fetch.withExpansionPaths(ProductProjectionExpansionModel.of().productType());
assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged")
.isEqualTo(asList(ExpansionPath.of("categories[*]")));
assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType")));
assertThat(fetch2).isNotSameAs(fetch);
See the test code.
This method also can be used to use the same expansions as in another request:
final ProductProjectionQuery query = ProductProjectionQuery.ofCurrent().withExpansionPaths(m -> m.categories());
final ProductProjectionSearch search = ProductProjectionSearch.ofCurrent().withExpansionPaths(query);
assertThat(query.expansionPaths())
.hasSize(1)
.as("reuse expansion spec from other request")
.isEqualTo(search.expansionPaths());
See the test code.
withExpansionPaths
in interface ReferenceExpansionDsl<CustomObject<T>,CustomObjectByIdGet<T>>
expansionPath
- the new expansion pathsCustomObjectByIdGet<T> withExpansionPaths(List<ExpansionPath<CustomObject<T>>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
.withExpansionPaths
in interface ReferenceExpansionDsl<CustomObject<T>,CustomObjectByIdGet<T>>
expansionPaths
- the new expansion paths