Tags a property to map from a different field name upon deserialization.
export class Example{
@DeserializeFieldName('bar')
foo: string;
}
const result = serializer.deserialize<Example>({ bar: 'hey' }, Example);
console.log(result.foo);
This will print hey
because the attribute with name bar
has been mapped into the foo
property.
Tags a property to map from a different field name.
export class Example{
@FieldName('bar')
foo: string;
}
const result = serializer.deserialize<Example>({ bar: 'hey' }, Example);
console.log(result.foo);
This will print hey
because the attribute with name bar
has been mapped into the foo
property.
Flags the given property as the discriminator.
@Parent({
discriminatorField: 'type',
allowSelf: true // This one is optional.
})
export class Vehicle{
type: string;
color: Color;
}
When the serializer will deserialize using this class, he will use Vehicle.type
value to find the right child.
You can se the allowSelf
flag to true if you want to get an instance of this class if no subclass is found with the
current discriminator value instead of an error.
Tags a property to map from a different field name upon serialization.
export class Example{
@SerializeFieldName('bar')
foo: string;
}
const obj = new Example();
obj.foo = 'baz'
const result = serializer.serialize(obj);
console.log(obj);
This will print the object as if foo
property was named bar
.
Tags a property as transient, meaning that it won't be used in serialization.
export class Example {
foo: string;
@Transient()
password: string;
}
const example = new Example();
example.foo = 'bar';
example.password = 'Super secret';
console.log(serializer.serialize(example));
This will print a JSON string of example
object, without password
property in it.
Generated using TypeDoc
Tags a property to be deserialized as a given class.
Example:
export class Foo{ @DeserializeAs(Bar) bar:Bar; }
Property