0

I'm using Angular on frontend and make request via HttpClient. The backend returns response

[
    {
        "id": 2,
        "simulatorId": 1,
        "name": "test",
        "created": "2020-04-20T12:10:19.278578",
        "isActive": false
    },
    {
        "id": 3,
        "simulatorId": 1,
        "name": "test",
        "created": "0001-01-01T00:00:00",
        "isActive": false
    }
]

TypeScript has class

class SimulatorSessionViewModel {
    id: number;
    simulatorId: number;
    name: string;
    created: Date;
    isActive: boolean;
}

Is it possible to automaticly create class from response?

Evgeny Naumov
  • 347
  • 1
  • 4
  • 15
  • Initiate the class and assign its properties? What do you want to achive, why dont you use simple json? – mamichels Apr 20 '20 at 09:00
  • For example, I have the field `created` which have type `Date` and I want to `created` field will automatically filled – Evgeny Naumov Apr 20 '20 at 09:09
  • Use `Object.assign`. You can otherwise use the json as is, unless you want to use methods on the class? – David Apr 20 '20 at 09:10
  • Yes. I want to field `created` was filled automaticlly with type `Date` and use methods of the `Date` class – Evgeny Naumov Apr 20 '20 at 10:05

0 Answers0