AfterDeserialize
@tsed/json-mapper
Usage
typescript
import { AfterDeserialize } from "@tsed/json-mapper";
See /packages/specs/json-mapper/src/types/decorators/afterDeserialize.ts.
Overview
ts
function AfterDeserialize(cb: AfterDeserializeCallback): ClassDecorator;
Description
Call the function after JsonMapper.
Example
typescript
@AfterDeserialize((data: Model) => { // After deserialize get the instance class
if (data.prop1 === 'VALUE' && data.prop2 !== 'VALUE2') {
throw BadRequest('MyMessage'); // or throw a ValidationError
} else {
data.prop2 = 'VALUE2';
return data;
}
})
class Model {
@Property()
prop1: string;
@Property()
prop2: string;
}