flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.17k stars 90 forks source link

Class members are ignored #295

Closed Mansi1 closed 2 months ago

Mansi1 commented 2 months ago

Basic example

class Super {
  constructor(
    public blue: number,
    public red: String,
    public date = new Date()
  ) {}
}

const data = SuperJSON.stringify(new Super(1, new String('sdfds')));
console.log(data);  //{"json":{"blue":1,"red":"sdfds","date":"2024-09-10T12:11:18.429Z"}}
Skn0tt commented 2 months ago

Take a look at https://github.com/flightcontrolhq/superjson/issues/227 - you're looking for SuperJSON.registerClass. Let me know if that helped!