Transformers
Convert values between their runtime type and their wire representation, per field.
A transformer converts one field between its in-memory type and its JSON representation. Attach it with the transformer option; Base instantiates it and calls fromJson on the way in, toJson on the way out.
The built-ins
DateJsonValueTransformer — Date ⇄ ISO-8601 string. Accepts a string, Date, or epoch number inbound:
CommaSeparatedJsonValueTransformer — string[] ⇄ "a,b,c". Made for query parameters:
JsonObjectValueTransformer — an embedded JSON object in a string value (?metadata={"key":"value"}); yields null when missing or invalid.
Write your own
Implement the two-method interface:
Note the option takes the class, not an instance — Base constructs it per use. Throw from fromJson for un-parseable input and the request fails as a 400 serialization error, before validation or your handler.
When to reach for one
Transformers are for representation mismatches: dates, money-as-cents, comma-packed lists, embedded JSON. If what you actually want is to reject values, that's a validation rule; if you want a different JSON key, that's the name option. Keep each mechanism doing its own job.