How can i pass a Map object with $session.$data?


Hi all, in my code i have something like this:

let map = new Map();
...code to fill the map...
this.$session.$data.next1 = map; 

While testing i see that this.$session.$data :{"next1":{}} , so it’s empty.

Do i need to pass it as a JSON string using JSON.stringify() and doing what is explained here ??
Or is there some workarounds?


I solved my problem without using Map and $session.$data. I needed to pass 2 param associated to each other after a button click. So, in the OptionItem i use .setKey(param1+’ '+param2) and then in ON_ELEMENT_SELECTED(), split the selectedElement.
Still, if there’s a way to pass a Map Object in $session.$data i would be happy to know.


I am using a class with a map object. Its serialize method is called automatically after the handler middleware finished:

serialize() {
    return JSON.stringify([...this.flagMap]);

and for each request its constructor is used to create the object from the session store:

  constructor(dbObject?: string) {

      this.flagMap = new Map(JSON.parse(dbObject));

Does that help @Alberto1 ?