Object Schema
Reviving regular objects
interface RevivalObjectSchema<T> {
type: ReviveConstructor<T>;
properties: { [key: string]: RevivalSchema<any> }
}const serialized = `{ "name": "John Smith", "job": { "title": "developer" } }`
/* Job model */
class Job {
title = ''
public getTitle() {
return this.title
}
}
/* Person model */
class Person {
name = ''
job: Job | null = null
public getName() {
return this.name
}
public getJob() {
return this.job
}
}
const schema: RevivalSchema<Person> = {
type: Person,
properties: {
job: Job,
},
}
const person = revive(serialized, schema)
console.log(person.getName()) // John Smith
console.log(person.getJob().getTitle()) // developerLast updated