Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface PropertyOptions

Defines SerializeProperty decorator options

Hierarchy

Index

Properties

Properties

Optional list

list: boolean

Used to map a collection of elements.

Example

 @Serialize()
 class MyClass extends Serializable {
     @SerializeProperty({
         list: true
     })
     values:string[];
 }

Deserialize

 let instance:MyClass = new MyClass();
 instance.deserialize({
     values: ['a', 'b', 'c']
 });

 console.log(instance.values); // Will output ['a', 'b', 'c']

Serialize

 let instance:MyClass = new MyClass();
 instance.values = ['a', 'b', 'c'];

 console.log(instance.serialize()); // Will output {values:['a','b','c']}

Optional map

map: string

Used to map to a different property name in the json object.

Example

 @Serialize()
 class MyClass extends Serializable {
     @SerializeProperty({
         map: 'first_name'
     })
     firstName:string;
 }

Deserialize

 let instance:MyClass = new MyClass();
 instance.deserialize({
     first_name: 'some value'
 });

 console.log(instance.firstName); // Will output 'some value'

Serialize

 let instance:MyClass = new MyClass();
 instance.firstName = 'value'

 console.log(instance.serialize()); // Will output {first_name:'value'}

Optional name

name: string

Used by the Serializer to locate properties in the _serializeMap. This property should only be set by the SerializeProperty

Optional root

root: string

Root path to use when mapping.

Example

 @Serialize({
     root: 'someObject'
 })
 class MyClass extends Serializable {
     @SerializeProperty()
     name:string;
 }

Deserialize

 let instance:MyClass = new MyClass();
 instance.deserialize({
     someObject: {
         name: 'some value'
     }
 });

 console.log(instance.name); // Will output 'some value'

Serialize

 let instance:MyClass = new MyClass();
 instance.name = 'value';

 console.log(instance.serialize()); // Will output {someObject:{name:'value'}}

Optional type

type: any

Specifies the type of the property.

Example

 @Serialize()
 class User extends Serializable {
     @SerializeProperty()
     firstName:string;
     @SerializeProperty()
     lastName:string;
 }

 @Serialize()
 class Profile extends Serializable {
     @SerializeProperty({
         type: User
     })
     user:User;
 }

Deserialize

 let profile:Profile = new Profile();
 profile.deserialize({
     user: {
         firstName: 'John',
         lastName: 'Doe'
     }
 });

 console.log(profile.user.firstName); // Will output 'John'
 console.log(profile.user.lastName); // Will output 'Doe'

Serialize

 let profile:Profile = new Profile();
 profile.user = new User();
 profile.user.firstName = 'John';
 profile.user.lastName = 'Doe';

 console.log(profile.serialize()); // Will output {user:{firstName:'John', lastName:'Doe'}}

Generated using TypeDoc