I am using Angular5 on a spring boot application. I am trying to return a Map in JSON.
Spring :
//some method
return ResponseEntity.ok((new Gson()).toJson(/*My map object*/));
Angular5 :
sql_list = new Map<string,string>();
this.myService.getQueries().subscribe(
data => {
console.log("Received data: ");
console.log(data);
this.sql_list = data;
console.log(this.sql_list.get("query1"));
}
);
In the client I can see that the data is well received using console.log :
Received data:
{
"query1" : "select * from test",
"query2" : "select * from test2",
"query3" : "select * from test3"
}
But sql_list
object gives me that error when trying to use map.get(string key)
method :
ERROR TypeError: _this.sql_list.get is not a function
Which mistake did I do there?
EDIT: following Florian answer this is working:
this.sql_list = new Map<string, string>(Object.entries(data));