Class WebPayloadParameterResolver

java.lang.Object
io.fluxzero.sdk.web.WebPayloadParameterResolver
All Implemented Interfaces:
ParameterResolver<HasMessage>

public class WebPayloadParameterResolver extends Object implements ParameterResolver<HasMessage>
Resolves a method parameter from the payload of a WebRequest.

This resolver is only applied to methods annotated with HandleWeb or any of its meta-annotations (e.g. HandlePost). It converts the deserialized payload to the method parameter's declared type.

Optionally, the resolver can enforce validation and authorization:

  • If validatePayload is true, the resolved payload is validated using assertValid().
  • If authoriseUser is true, the current User must be authorized to execute the payload’s type via assertAuthorized().
See Also:
  • Constructor Details

    • WebPayloadParameterResolver

      public WebPayloadParameterResolver()
  • Method Details

    • resolve

      public Function<HasMessage, Object> resolve(Parameter p, Annotation methodAnnotation)
      Resolves the value for the given method parameter by converting the message payload to the expected parameter type. If configured, it also validates and authorizes the payload.
      Specified by:
      resolve in interface ParameterResolver<HasMessage>
      Parameters:
      p - the method parameter to resolve
      methodAnnotation - the annotation on the handler method (typically @HandleWeb)
      Returns:
      a function that resolves the parameter from a HasMessage instance
    • test

      public boolean test(HasMessage m, Parameter p)
      Description copied from interface: ParameterResolver
      Determines whether a given message should be passed to a handler method based on this parameter's characteristics.

      This hook is used after ParameterResolver.matches(Parameter, Annotation, M) is invoked but before ParameterResolver.resolve(Parameter, Annotation) and can thus be used to prevent other parameter resolvers from supplying a candidate for parameter injection.

      Specified by:
      test in interface ParameterResolver<HasMessage>
      Parameters:
      m - the message being evaluated
      p - the method parameter to test
      Returns:
      true if the message should be processed, false if it should be filtered out
    • matches

      public boolean matches(Parameter parameter, Annotation methodAnnotation, HasMessage value)
      Determines whether this resolver should be used for the given method parameter. This resolver is active for any method annotated with HandleWeb or any annotation that is meta-annotated with it.
      Specified by:
      matches in interface ParameterResolver<HasMessage>
      Parameters:
      parameter - the method parameter
      methodAnnotation - the annotation on the method
      value - the incoming message
      Returns:
      true if the resolver is applicable to this parameter
    • mayApply

      public boolean mayApply(Executable method, Class<?> targetClass)
      Description copied from interface: ParameterResolver
      Returns true if this resolver might apply to the given method. Implementations should perform only inexpensive checks and never throw.
      Specified by:
      mayApply in interface ParameterResolver<HasMessage>
      Parameters:
      method - the handler method or constructor
      targetClass - the declaring or target class
      Returns:
      true if this resolver could apply, false otherwise