R- The response type which will be matched against and converted to
public class OptionalResponseType<R> extends AbstractResponseType<Optional<R>>
ResponseTypeimplementation 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
|Constructor and Description|
|Modifier and Type||Method and Description|
Match the query handler its response
equals, getExpectedResponseType, hashCode, isArray, isArrayOfExpectedType, isAssignableFrom, isGenericArrayOfExpectedType, isGenericArrayType, isGenericAssignableFrom, isIterableOfExpectedType, isParameterizedType, isParameterizedTypeOfExpectedType, isStreamOfExpectedType, isTypeVariable, isWildcardType, isWildcardTypeWithMatchingUpperBound, unwrapIfTypeFuture
@ConstructorProperties(value="expectedResponseType") public OptionalResponseType(Class<R> expectedResponseType)
OptionalResponseTypewith the given
expectedResponseTypeas 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 returned
public boolean matches(Type responseType)
Typewith 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
Typeof the query handler which is matched against
Objectinto the type
ResponseTypeinstance. Should only be called if
ResponseType.matches(Type)returns true. It is unspecified what this function does if the
Objectto convert into
public Class responseMessagePayloadType()
Classrepresenting the type of the payload to be contained in the response message.
Classrepresenting the type of the payload to be contained in the response message
public ResponseType<?> forSerialization()
ResponseTypeinstance 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.
ResponseTypeinstance describing a type suitable for serialization
Copyright © 2010–2021. All rights reserved.