class MyClass {
myString: string;
myDate: Date;
}
function foo() {
const myClassArray: MyClass[] = ....
return JSON.stringify(myClassArray); // or expressApp.status(200).json(myClassArray);
}
foo
will retun a json
string with myDate
a string following the ISO standard of YYYY-MM-DDThh:mm:ssZ
.
I'd like to be able to customize how JSON.stringify()
is serializing myDate
.
I'm not stuck to JSON.stringify() to achieve what I want, although I prefer it since express.json() is using it behind the scene. In case this is not possible, is there a serialization library that will help me achieve what I want? Maybe a library that implements a decorator pattern? or maybe a more native solution?