[SalesForce] Deserialize Json String into from Map> in apex

I am currently working on a Lightning component where the data that I am passing from my apex controller ( in the doInit() ) is in the form of Map<String,List<CustomWrapper>>.

When Some modifications to the records are made, I have to pass this whole Map from component to apex controller.

To achieve this, I have first converted this map into Json using stringify() in my JS Controller and then passed this string version of json to my apex method.

Now, when I receive this string in the apex method, I am unable to convert it back in the form of Map<String,List<CustomWrapper>>.

How do I do this?

P.S. – CustomWrapper is a wrapper class with some string variables in it.

Best Answer

You can use JSON.deserialize in you apex Class. Hope this example will help you.

Apex controller

public static void onInit(String memberJson){
  Map<String,List<CustomWrapper>> myMap =