R
- The response type which will be matched against and converted topublic class OptionalResponseType<R> extends AbstractResponseType<Optional<R>>
ResponseType
implementation that will match with query handlers which return a single instance of the
expected response type, but returns that as an Optional containing the result. If matching succeeds, the ResponseType.convert(Object)
function will be called, which will wrap the query handler's response into an
Optional.
Note that this ResponseType
will declare the same expectations on the Query Result as the ResponseType
returned by InstanceResponseType
. The difference is that the result provided by this ResponseType
is wrapped in an Optional
.
expectedResponseType
MATCH, NO_MATCH
Constructor and Description |
---|
OptionalResponseType(Class<R> expectedResponseType)
Instantiate a
OptionalResponseType with the given expectedResponseType as the type to be matched
against and to which the query response should be converted to. |
Modifier and Type | Method and Description |
---|---|
Optional<R> |
convert(Object response)
|
ResponseType<?> |
forSerialization()
Returns the
ResponseType instance that should be used when serializing responses. |
boolean |
matches(Type responseType)
Match the query handler its response
Type with this implementation its responseType R . |
Class |
responseMessagePayloadType()
Returns a
Class representing the type of the payload to be contained in the response message. |
String |
toString() |
equals, getExpectedResponseType, hashCode, isArray, isArrayOfExpectedType, isAssignableFrom, isGenericArrayOfExpectedType, isGenericArrayType, isGenericAssignableFrom, isIterableOfExpectedType, isParameterizedType, isParameterizedTypeOfExpectedType, isPublisherOfExpectedType, isStreamOfExpectedType, isTypeVariable, isWildcardType, isWildcardTypeWithMatchingUpperBound, projectReactorOnClassPath, unwrapIfTypeFuture
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
convertExceptional, matchRank
@ConstructorProperties(value="expectedResponseType") public OptionalResponseType(Class<R> expectedResponseType)
OptionalResponseType
with the given expectedResponseType
as the type to be matched
against and to which the query response should be converted to.expectedResponseType
- the response type which is expected to be matched against and returnedpublic boolean matches(Type responseType)
Type
with this implementation its responseType R
. Will
return true if the expected type is assignable to the response type, taking generic types into account.responseType
- the response Type
of the query handler which is matched againstpublic Optional<R> convert(Object response)
ResponseType
response
of type Object
into the type R
of this ResponseType
instance. Should only be called if ResponseType.matches(Type)
returns true. It is
unspecified what this function does if the ResponseType.matches(Type)
returned false.response
- the Object
to convert into R
response
of type R
public Class responseMessagePayloadType()
ResponseType
Class
representing the type of the payload to be contained in the response message.Class
representing the type of the payload to be contained in the response messagepublic ResponseType<?> forSerialization()
ResponseType
ResponseType
instance that should be used when serializing responses. This method has a
default implementation that returns this
. Implementations that describe a Response Type that is not
suited for serialization, should return an alternative that is suitable, and ensure the ResponseType.convert(Object)
is capable of converting that type of response to the request type in this instance.ResponseType
instance describing a type suitable for serializationCopyright © 2010–2023. All rights reserved.