MatrixVariable class

Binds a matrix variable from a specific path segment of the URI to a method parameter.

Matrix variables are key-value pairs embedded in URI path segments using semicolon syntax. They provide a way to attach metadata to individual path segments in a RESTful URL structure.

Matrix Variable Syntax

/resources/{id};key=value/other;param=42

Parameters

  • value: Name of the matrix variable to bind
  • pathVar: The name of the path variable segment containing the matrix variable
  • required: Whether this variable is mandatory (default: true)
  • defaultValue: Fallback value if the matrix variable is missing

Example

@RestController()
class ProductController {
  @GetMapping('/products/{category}/items/{id}')
  Product getProduct(
    @MatrixVariable(value: 'sort', pathVar: 'category') String sortBy,
    @MatrixVariable(value: 'version', pathVar: 'id', required: false) String? version
  ) {
    // URL: /products/electronics;sort=price/items/123;version=2
    // sortBy = "price", version = "2"
    return productService.findProduct(sortBy: sortBy, version: version);
  }
}

Framework Integration

This annotation is processed by the MatrixVariableResolver which extracts matrix variables from the appropriate path segments.

Inheritance
Annotations
  • @Target.new({TargetKind.parameter})
  • @ResolvedBy(MatrixVariableResolver())

Constructors

MatrixVariable({String? value, String? pathVar, bool required = true, String? defaultValue})
Binds a matrix variable from a specific path segment of the URI to a method parameter.
const

Properties

annotationType Type
Returns the annotation _type of this annotation.
no setterinherited
defaultValue String?
Default value to use if the request element is not present.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
pathVar String?
The name of the path variable segment that contains this matrix variable.
final
required bool
Whether the request element is mandatory.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String?
Name of the request element to bind.
finalinherited

Methods

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
override
equals(Object other) bool
Checks whether the given object is logically equivalent to this annotation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of this annotation.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited