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.01k stars 87 forks source link

Class members are ignored #295

Closed Mansi1 closed 1 week ago

Mansi1 commented 1 week 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 1 week ago

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