Class JsonPayloadParameterResolver
java.lang.Object
io.fluxzero.sdk.tracking.handling.JsonPayloadParameterResolver
- All Implemented Interfaces:
ParameterResolver<DeserializingMessage>
public class JsonPayloadParameterResolver
extends Object
implements ParameterResolver<DeserializingMessage>
A
ParameterResolver that converts the message payload to the parameter's declared type
if that type is assignable to JsonNode.
This resolver supports handler parameters that accept JSON payloads directly as JsonNode
instances. When matched, it uses HasMessage.getPayloadAs(java.lang.reflect.Type) to
deserialize the message payload into the declared parameter type.
Example usage:
@HandleCommand(allowedClasses = CreateProject.class)
void handle(JsonNode command) {
// The message payload is automatically converted to a JsonNode instance
}
This resolver only applies to handler methods or constructors that declare at least one parameter
of a type assignable to JsonNode. Additionally, the format of the message payload must be
JSON, as indicated by Data.JSON_FORMAT.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanmatches(Parameter parameter, Annotation methodAnnotation, DeserializingMessage value) Determines whether this resolver matches the given parameter.booleanmayApply(Executable method, Class<?> targetClass) Indicates whether this resolver may apply to the given method.resolve(Parameter parameter, Annotation methodAnnotation) Returns a function that converts the message payload to the expected parameter type usingHasMessage.getPayloadAs(java.lang.reflect.Type).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ParameterResolver
determinesSpecificity, test
-
Constructor Details
-
JsonPayloadParameterResolver
public JsonPayloadParameterResolver()
-
-
Method Details
-
resolve
public Function<DeserializingMessage, Object> resolve(Parameter parameter, Annotation methodAnnotation) Returns a function that converts the message payload to the expected parameter type usingHasMessage.getPayloadAs(java.lang.reflect.Type).- Specified by:
resolvein interfaceParameterResolver<DeserializingMessage>- Parameters:
parameter- the handler method parameter to resolvemethodAnnotation- the handler method annotation, if present- Returns:
- a function that produces the converted JSON payload value
-
matches
public boolean matches(Parameter parameter, Annotation methodAnnotation, DeserializingMessage value) Determines whether this resolver matches the given parameter.A parameter is considered a match if it is assignable to
JsonNodeand the payload format of the message equalsData.JSON_FORMAT.- Specified by:
matchesin interfaceParameterResolver<DeserializingMessage>- Parameters:
parameter- the parameter being checkedmethodAnnotation- the annotation on the handler methodvalue- the message instance to use for resolution- Returns:
trueif the parameter can be resolved and assigned to,falseotherwise
-
mayApply
Indicates whether this resolver may apply to the given method.This implementation returns
trueif any of the method's parameters are assignable toJsonNode.- Specified by:
mayApplyin interfaceParameterResolver<DeserializingMessage>- Parameters:
method- the handler method or constructortargetClass- the declaring or target class- Returns:
trueif this resolver could apply,falseotherwise
-