I have a class with a custom toJSON
implementation so that I can override the default serialization done by JSON.stringify
.
When testing locally it works as expected but on production the custom toJSON
method is not called:
class Foo {
toJSON() {
return "Hello World"
}
}
console.log(JSON.stringify({foo: new Foo()}));
// returns: { foo: "Hello World" } on local
// returns: { foo: {} } on production
I am pretty sure this is happening because our production builds are handled by Angular CLI with the --prod
flag enabled. This causes uglifyjs
to kick in and rename toJSON
to some cryptic value which ofcourse is not picked up by JSON.stringify
.
Is it possible to tell Angular CLI to ignore special function names such as toJSON
in the minfication/uglification process?