title: JSON deserialization for Typescript class
body: <p>Assume I have this class in TypeScript that accepts a number and customizes the JSON serialization by converting it into human readable date and labelling it as dob.</p>
  <pre><code>    class Foo {
          private readonly seconds: number
          constructor(seconds: number) {
              this.seconds = seconds;
          }
          toJSON(){
              return {dob: new Date(this.seconds * 1000).toDateString()};
          }
      }
  </code></pre>
  <p>Now I construct an object of <code>Foo</code> and serialize it to JSON</p>
  <pre><code>    const foo = new Foo(1663962526);
      console.log(JSON.stringify(foo));
  </code></pre>
  <p>and I get this as output</p>
  <pre><code>{\&quot;dob\&quot;:\&quot;Fri Sep 23 2022\&quot;}
  </code></pre>
  <p>now I take this String back and try to form the instance of Foo again.</p>
  <pre><code>    const reconstructedFoo = JSON.parse(&quot;{\&quot;dob\&quot;:\&quot;Fri Sep 23 2022\&quot;}&quot;)
      console.log(reconstructedFoo.seconds) // this is undefined
      console.log(isNaN(reconstructedFoo.seconds))
  </code></pre>
  <p>Ofcourse, it doesn't fit into shape of <code>Foo</code> - how do override the deserialization of JSON into instance (like i did by toJSON for serialization)</p>