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 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 using HasMessage.getPayloadAs(java.lang.reflect.Type).
      Specified by:
      resolve in interface ParameterResolver<DeserializingMessage>
      Parameters:
      parameter - the handler method parameter to resolve
      methodAnnotation - 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 JsonNode and the payload format of the message equals Data.JSON_FORMAT.

      Specified by:
      matches in interface ParameterResolver<DeserializingMessage>
      Parameters:
      parameter - the parameter being checked
      methodAnnotation - the annotation on the handler method
      value - the message instance to use for resolution
      Returns:
      true if the parameter can be resolved and assigned to, false otherwise
    • mayApply

      public boolean mayApply(Executable method, Class<?> targetClass)
      Indicates whether this resolver may apply to the given method.

      This implementation returns true if any of the method's parameters are assignable to JsonNode.

      Specified by:
      mayApply in interface ParameterResolver<DeserializingMessage>
      Parameters:
      method - the handler method or constructor
      targetClass - the declaring or target class
      Returns:
      true if this resolver could apply, false otherwise