I've been struggling with converting the JSON object returned from the service to the Directory class. The issue is that the Directory class has an 'expanded' property which is not present in the JSON object. I've tried various methods over the past few days but haven't had any luck.
Thank you in advance for any help or guidance on this matter.
export class Directory {
type: string;
name: string;
expanded: false;
directories: Directory[];
files: File[];
}
export class File {
type: string;
name: string;
fileExtension: string;
size: string;
lastModified: string;
downloadUrl: string;
}
[
{
"type": "directory",
"name": "DIR A",
"directories": [],
"files": [
{
"type": "file",
"name": "FILEN.pdf",
"fileExtension": ".pdf",
"size": 1000,
"lastModified": "2020-06-17",
"downloadUrl": "http://example.com/filename.pdf"
},
{
"type": "file",
"name": "FILEN-1.pdf",
"fileExtension": ".pdf",
"size": 1000,
"lastModified": "2020-06-15",
"downloadUrl": "http://example.com/filename-1.pdf"
}
]
},
{
"type": "directory",
"name": "DIR B",
"directories": [],
"files": [
{
"type": "file",
"name": "FILEN-2.pdf",
"fileExtension": ".pdf",
"size": 1000,
"lastModified": "2020-06-12",
"downloadUrl": "http://example.com/filename-2.pdf"
}
]
}
]
I attempted the following approach:
this.api.getFileUrl().subscribe((response:any) => {
let directory: Directory = JSON.parse(JSON.stringify(response));
});
Upon debugging, I noticed that the 'expanded' property is missing in the directory object. By the way, I am relatively new to Typescript and Angular.