I am trying to cast a JSON object like the following example:
class Person {
constructor(
public firstName,
public lastName
) {}
function getName() {
return this.firstName + “ “ + this.lastName;
}
}
The goal is to parse the JSON which looks like this:
{
firstName: “Max“,
lastName: “Mustermann“
}
to an instance of the above class to access all properties and methods.
Is there an easy way to create a function which can make such a functionality possible for such type of JSONs/classes? Also nested objects should be possible.
I can write a factory method for every different class but there should be an better way to get such functionality.