Here is a sample of my class structure:
export class Patient {
constructor(public id: number, public name: string, public location: string, public bedId: number, public severity: string,
public trajectory: number, public vitalSigns: [GraphData[]], public latestReading: GraphData[]){
}
public get getCombinedVSData(): Array<GraphData>{
let combinedVitalSigns: GraphData[] = [];
for (let data of this.vitalSigns){
combinedVitalSigns.push(data[0]);
}
return combinedVitalSigns;
}
}
When I try to print out one of the patients from the service,
console.log(this.patientService.patients[0]);
This is the output I receive:
https://i.sstatic.net/GKdpv.png
For drag and drop functionality in my application, I need to convert the patient object to JSON format:
let jsonData=JSON.stringify(this.patientService.patients[0]);
However, upon converting it back to a JavaScript object and printing it,
console.log(JSON.parse(jsonData));
The resulting output no longer contains the Patient
class identifier and the getCombinedVSData
getter function.
Is this the expected behavior when working with JSON conversion? How can I ensure that the getter remains intact on the object during JSON transformation? Thank you.