# Decorator BeforeDeserialize

Decorator schema property private
Module
import { BeforeDeserialize } from "@tsed/json-mapper/src/decorators/beforeDeserialize"
Source/packages/json-mapper/src/decorators/beforeDeserialize.ts

# Overview

function BeforeDeserialize(cb: BeforeDeserializeCallback): ClassDecorator;

# Description

Call the function before JsonMapper.

# Example

@BeforeDeserialize((data: Record<string, unknown>) => { // Before deserialize get the data
   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;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Other topics