+ Start a Discussion
DeepikareddyDeepikareddy 

Deserilize the dynamci jsondata and bind to wrapperclass

public class testingarryfuction {

   public StateInfodetails StateInfodetailswraper{get;set;}
   public string Stateidselected{get;set;}
   public boolean isSelected{get;set;}
    public  testingarryfuction (){
    
    
    
    string teststring ='{ "sucess":1,"data":{"Stateidselected":"2","StateInfodetails":{"stateName": "Andrapradesh","value": "apx" ,"rating":5},"isSelected":true}}';
    Map<String, Object> maptest =   (Map<String, Object>) JSON.deserializeUntyped(teststring);
    system.debug('mapped and deserialized data is::'+maptest);
         
           
      Object ob = (Object)maptest.get('data');    
       system.debug('get data is::'+ob);
       
     String srlze  = System.JSON.serialize(ob); 
      system.debug('again deserailized is ::'+srlze );
      
       StateInfodetailswraper = (StateInfodetails)System.JSON.deserialize(srlze,StateInfodetails.class);
     system.debug('deserilize using the wrapperclass::::::'+StateInfodetailswraper );
      system.debug(StateInfodetailswraper.stateName);
    }
    
    
     //this is a wrapper class 
     public class StateInfodetails{
     public string stateName{get;set;}
     public string  value{get;set;}
     public integer rating{get;set;}
    
   }

   
   
   
  
}

After debugging , iam getting the value as: NULL...!

Can anyone have a solution to serialize it .. thank you ...!
Best Answer chosen by Deepikareddy
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Deepika

You have to access the "StateInfodetails" node.
Which means
 String srlze = System.JSON.serialize(ob);
system.debug('again deserailized is ::'+srlze );
this would serealize the data node which has "Stateidselected" and "StateInfodetails" node.In order to parse the StateInfodetails instance you will have to access forst data then StateInfodetails:

Object ob = (Object)maptest.get('data');   
 system.debug('get data is::'+ob);
ob.get('StateInfodetails');

and then use it to serialize.

Cheers!!!