Class OptionalResponseType<R>
java.lang.Object
org.axonframework.messaging.responsetypes.AbstractResponseType<Optional<R>>
org.axonframework.messaging.responsetypes.OptionalResponseType<R>
- Type Parameters:
R- The response type which will be matched against and converted to
- All Implemented Interfaces:
Serializable,ResponseType<Optional<R>>
A
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.
- Since:
- 4.2
- Author:
- Allard Buijze
- See Also:
-
Field Summary
Fields inherited from class org.axonframework.messaging.responsetypes.AbstractResponseType
expectedResponseTypeFields inherited from interface org.axonframework.messaging.responsetypes.ResponseType
MATCH, NO_MATCH -
Constructor Summary
ConstructorsConstructorDescriptionOptionalResponseType(Class<R> expectedResponseType) Instantiate aOptionalResponseTypewith the givenexpectedResponseTypeas the type to be matched against and to which the query response should be converted to. -
Method Summary
Modifier and TypeMethodDescriptionResponseType<?> Returns theResponseTypeinstance that should be used when serializing responses.booleanMatch the query handler its responseTypewith this implementation its responseTypeR.Returns aClassrepresenting the type of the payload to be contained in the response message.toString()Methods inherited from class org.axonframework.messaging.responsetypes.AbstractResponseType
equals, getExpectedResponseType, hashCode, isArray, isArrayOfExpectedType, isAssignableFrom, isGenericArrayOfExpectedType, isGenericArrayType, isGenericAssignableFrom, isIterableOfExpectedType, isParameterizedType, isParameterizedTypeOfExpectedType, isPublisherOfExpectedType, isStreamOfExpectedType, isTypeVariable, isWildcardType, isWildcardTypeWithMatchingUpperBound, projectReactorOnClassPath, unwrapIfTypeFutureMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.messaging.responsetypes.ResponseType
convertExceptional, matchRank
-
Constructor Details
-
OptionalResponseType
@ConstructorProperties("expectedResponseType") public OptionalResponseType(Class<R> expectedResponseType) Instantiate aOptionalResponseTypewith the givenexpectedResponseTypeas the type to be matched against and to which the query response should be converted to.- Parameters:
expectedResponseType- the response type which is expected to be matched against and returned
-
-
Method Details
-
matches
Match the query handler its responseTypewith this implementation its responseTypeR. Will return true if the expected type is assignable to the response type, taking generic types into account.- Parameters:
responseType- the responseTypeof the query handler which is matched against- Returns:
- true if the response type is assignable to the expected type, taking generic types into account
-
convert
Description copied from interface:ResponseTypeConverts the givenresponseof typeObjectinto the typeRof thisResponseTypeinstance. Should only be called ifResponseType.matches(Type)returns true. It is unspecified what this function does if theResponseType.matches(Type)returned false.- Parameters:
response- theObjectto convert intoR- Returns:
- a
responseof typeR
-
responseMessagePayloadType
Description copied from interface:ResponseTypeReturns aClassrepresenting the type of the payload to be contained in the response message.- Returns:
- a
Classrepresenting the type of the payload to be contained in the response message
-
forSerialization
Description copied from interface:ResponseTypeReturns theResponseTypeinstance that should be used when serializing responses. This method has a default implementation that returnsthis. Implementations that describe a Response Type that is not suited for serialization, should return an alternative that is suitable, and ensure theResponseType.convert(Object)is capable of converting that type of response to the request type in this instance.- Returns:
- a
ResponseTypeinstance describing a type suitable for serialization
-
toString
-