Change the default serialize behaviour for Date
Closed this issue · 2 comments
joey-he8x commented
i use cerialize before insert/update records to mongodb.
Is there a way i can aviod serialize Date to ISOString, i want to keep it as Date, or serialize it into Number, but neither works.
TheBinaryFox commented
In version 2.0, you can use @autoserializeUsing(transforms : SerializeAndDeserializeFns, customKey? : string)
to do that.
weichx commented
you can use a custom serializer in version 1, check the docs, you can provide a @autoserializeAs
with an object that defines your serializer. Just do the same for your Date
type
const MoneySerializer = {
Serialize(json : any) : any {
return { amount: value, currency: "EUR" };
},
Deserialize(json : any) : any {
return parseFloat(json.amount);
}
};
class CustomThing {
@autoserializeAs(MoneySerializer) public amount : number;
}