-
Notifications
You must be signed in to change notification settings - Fork 0
from json
awekrx edited this page May 29, 2026
·
1 revision
import { fromJson } from '@dev-suite/decorators/from-json'
parameter
Parse JSON string argument into object.
-
JSON.parsein every endpoint - Repeated parse error handling
class WebhookController {
ingest(payload: string) {
const parsed = JSON.parse(payload);
return this.handler.handle(parsed);
}
}import { fromJson } from '@dev-suite/decorators/from-json';
class WebhookController {
ingest(@fromJson() payload: WebhookPayload) {
return this.handler.handle(payload);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class JobController {
run(configRaw: string) {
const config = JSON.parse(configRaw);
return this.jobs.run(config);
}
}import { fromJson } from '@dev-suite/decorators/from-json';
class JobController {
run(@fromJson() configRaw: JobConfig) {
return this.jobs.run(configRaw);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.