Used to map a collection of elements.
@Serialize()
class MyClass extends Serializable {
@SerializeProperty({
list: true
})
values:string[];
}
let instance:MyClass = new MyClass();
instance.deserialize({
values: ['a', 'b', 'c']
});
console.log(instance.values); // Will output ['a', 'b', 'c']
let instance:MyClass = new MyClass();
instance.values = ['a', 'b', 'c'];
console.log(instance.serialize()); // Will output {values:['a','b','c']}
Used to map to a different property name in the json object.
@Serialize()
class MyClass extends Serializable {
@SerializeProperty({
map: 'first_name'
})
firstName:string;
}
let instance:MyClass = new MyClass();
instance.deserialize({
first_name: 'some value'
});
console.log(instance.firstName); // Will output 'some value'
let instance:MyClass = new MyClass();
instance.firstName = 'value'
console.log(instance.serialize()); // Will output {first_name:'value'}
Used by the Serializer to locate properties in the _serializeMap
. This property should only be set by the SerializeProperty
Root path to use when mapping.
@Serialize({
root: 'someObject'
})
class MyClass extends Serializable {
@SerializeProperty()
name:string;
}
let instance:MyClass = new MyClass();
instance.deserialize({
someObject: {
name: 'some value'
}
});
console.log(instance.name); // Will output 'some value'
let instance:MyClass = new MyClass();
instance.name = 'value';
console.log(instance.serialize()); // Will output {someObject:{name:'value'}}
Specifies the type of the property.
@Serialize()
class User extends Serializable {
@SerializeProperty()
firstName:string;
@SerializeProperty()
lastName:string;
}
@Serialize()
class Profile extends Serializable {
@SerializeProperty({
type: User
})
user:User;
}
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'
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
Defines SerializeProperty decorator options