A project entity has the following field(java):
Map<String, String> employeeEmailToLoggedTimeMap = new HashMap<>();
I serialize the project with JSON and send it to my Angular frontend. The Map gets transformed into this form:
"employeeEmailToLoggedTimeMap":{
"someEmail123123@email.com":"23",
"someEmail123132423@email.com":"123",
"someEmail1232341123@email.com":"12",
"someEmail123123123@email.com":"23"
}
In Angular, i defined the field of the object im trying to receive the following way:
employeeEmailToLoggedTimeMap?: Map<string, string>;
When i do a GET-request to receive all projects
getProjects(): Observable<Project[]> {
return this.http.get<Project[]>(BASE_URL, this.authService.setHeaders('application/json'))
.pipe(
catchError(this.handleService.error.bind(this))
)
}
the empoyeeEmailToLoggedTimeMap
data isn´t transformed to a map. I receive the data without errors, but none of the map operators work.
For example, if i did
getProjects(): Observable<Project[]> {
return this.http.get<Project[]>(BASE_URL, this.authService.setHeaders('application/json'))
.pipe(
tap(projects => projects.forEach(project => {
console.log(project.employeeEmailToLoggedTimeMap);
console.log(project.employeeEmailToLoggedTimeMap.size);
})),
catchError(this.handleService.error.bind(this))
)
}
it would log all the data saved in project.employeeToLoggedTimeMap
, but project.employeeEmailToLoggedTimeMap.size
would return undefined and all other map operators don´t work too. So it seems like it does not recognize and transform the data into the map. So, how would i transform the data i get into the map i want?