T
- The type of the value of the custom object.public interface CustomObjectByKeyGet<T> extends MetaModelGetDsl<CustomObject<T>,CustomObject<T>,CustomObjectByKeyGet<T>,CustomObjectExpansionModel<CustomObject<T>>>
SphereRequest
to fetch one CustomObject
by container and key.
withCustomObject(client(), existingCustomObject -> { final String container = existingCustomObject.getContainer(); final String key = existingCustomObject.getKey(); final CustomObjectByKeyGet<Foo> fetch = CustomObjectByKeyGet.of(container, key, Foo.class); final CustomObject<Foo> customObject = client().executeBlocking(fetch); assertThat(customObject).isNotNull(); assertThat(customObject).isEqualTo(existingCustomObject); });
See the test code.
CustomObject
Modifier and Type | Method and Description |
---|---|
List<ExpansionPath<CustomObject<T>>> |
expansionPaths() |
static <T> CustomObjectByKeyGet<T> |
of(String container,
String key,
Class<T> valueClass)
Creates an object to fetch a custom object by the container and key with POJO mapping.
|
static <T> CustomObjectByKeyGet<T> |
of(String container,
String key,
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 CustomObjectByKeyGet<com.fasterxml.jackson.databind.JsonNode> |
ofJsonNode(String container,
String key)
Creates an object to fetch a custom object by the container and get the result as
JsonNode . |
CustomObjectByKeyGet<T> |
plusExpansionPaths(ExpansionPath<CustomObject<T>> expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
CustomObjectByKeyGet<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 . |
CustomObjectByKeyGet<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> CustomObjectByKeyGet<T> of(String container, String key, Class<T> valueClass)
T
- the type of the value in the custom objectcontainer
- container of the custom object to fetchkey
- key of the custom object to fetchvalueClass
- the class of the value, if it not uses generics like lists, typically for POJOsstatic <T> CustomObjectByKeyGet<T> of(String container, String key, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeReference)
T
- the type of the value in the custom objectcontainer
- container of the custom object to fetchkey
- key of the custom object to fetchvalueTypeReference
- the type reference of the value of the custom objectstatic CustomObjectByKeyGet<com.fasterxml.jackson.databind.JsonNode> ofJsonNode(String container, String key)
JsonNode
.container
- container of the custom object to fetchkey
- key of the custom object to fetchList<ExpansionPath<CustomObject<T>>> expansionPaths()
expansionPaths
in interface ExpansionPathContainer<CustomObject<T>>
expansionPaths
in interface ReferenceExpansionSupport<CustomObject<T>>
CustomObjectByKeyGet<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>,CustomObjectByKeyGet<T>>
expansionPath
- the new expansion path to add to the existing onesCustomObjectByKeyGet<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>,CustomObjectByKeyGet<T>>
expansionPath
- the new expansion pathsCustomObjectByKeyGet<T> withExpansionPaths(List<ExpansionPath<CustomObject<T>>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
.withExpansionPaths
in interface ReferenceExpansionDsl<CustomObject<T>,CustomObjectByKeyGet<T>>
expansionPaths
- the new expansion paths