ParamParse<P, R> class abstract

Abstract class for parameter parsing and serialization in Vaden.

The ParamParse interface defines a contract for converting between parameter types and JSON-serializable types in the Vaden framework. Implementations of this interface can be used with the @UseParse annotation to customize how request parameters are parsed and how response values are serialized.

Type parameters:

  • P: The parameter type (the dart type used in your code)
  • R: The representation type (typically a JSON-serializable type)

Example:

class DateTimeParser extends ParamParse<DateTime, String> {
  const DateTimeParser();

  @override
  String toJson(DateTime param) => param.toIso8601String();

  @override
  DateTime fromJson(String json) => DateTime.parse(json);
}

@Controller('/api/events')
class EventController {
  @Get('/')
  Future<Response> getEvents(
    Request request,
    @Query('start') @UseParse(DateTimeParser) DateTime startDate,
  ) {
    // startDate is automatically parsed from the query parameter
    // using the DateTimeParser
    return Response.ok('Events after $startDate');
  }
}

Constructors

ParamParse()
Creates a ParamParse instance.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

fromJson(R json) → P
Converts a JSON-serializable value of type R to its parameter type P.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson(P param) → R
Converts a parameter of type P to its JSON-serializable representation of type R.
toString() → String
A string representation of this object.
inherited

Operators

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