+ Start a Discussion
vignesh balasubramanian 14vignesh balasubramanian 14 

How to Display Wrapper Class Variable in Apex Controller

Hi Everyone,

This is my Wrapper Class:
---------------------------------

public class Restaurantwrapper
{
    public cls_nearby_restaurants[] nearby_restaurants;
    class cls_nearby_restaurants 
    {
        public cls_restaurant restaurant;
    }
    class cls_restaurant 
    {
        public String name;
    }
    public static Restaurantwrapper parse(String json){
        return (Restaurantwrapper) System.JSON.deserialize(json, Restaurantwrapper.class);
    }
}

This is my Controller:
----------------------

  @future(callout=true)
    public static void futuremethod(Decimal lat,Decimal lng,String S)
    {
        system.debug('future called');
        HttpRequest req = new HttpRequest();
        req.setEndPoint(S);
        req.setMethod('GET');
        req.setHeader('Accept', 'application/json');
        Http http = new Http();
        HttpResponse res;
        if(!Test.isRunningTest())
        {
            res = http.send(req);
            Restaurantwrapper reswrapper = (Restaurantwrapper)JSON.deserialize(res.getBody(), Restaurantwrapper.class);
            for(Integer i=0;i<reswrapper.nearby_restaurants.size();i++)
            {
                //Here I want to assign restaurant name to a string variable
                //EX: String name=reswrapper.nearby_restaurants(i).restaurant.name;

            }
        }
    }
    
    I need to assign restaurant name to string variable,but the above code is not working.Provide me the solution for this.
    
    Thanks in Advance,
    Vignesh.B
AvaneeshAvaneesh
Hi 

you can call like an inner class in Java
// make sure all data member are public 

Restaurantwrapper.cls_restaurant  innerClass = new Restaurantwrapper.cls_restaurant();
​String name = innerClass.name
if this was helpful don't forget to mark as best answer
Thank you
Avaneesh Singh 

 
vignesh balasubramanian 14vignesh balasubramanian 14
Hi Avaneesh,

Each time cls_restaurant class create new name and nearby_restaurant[] stores all the values.
How to assign all the names one by one  on for loop iteration..

Thanks,
Vignesh.B