0
{
    "Filters": [{
        "Decription": "Default",
        "FieldSelected": {
            "AppointmentDate": true,
            "AppointmentDateOrder": 1            
            "ptStatusOrder": 3
        },
        "FilterID": 1
    }, {
        "Decription": "chart",
        "FieldSelected": {
            "AppointmentDate": true,
            "AppointmentDateOrder": 1,           
            "ptStatusOrder": 0
        },
        "FilterID": 2
    }]
}

I am getting a response of this structure, how do i map it to my POJO class. Can anyone give a sample POJO class for this json structure. I am using Gson for Request and Response.

1
  • 1
    Hint: It's an object that has List of Filter. Filter in an object that has three attributes Description, FilterId, and another object called FieldSelected. Field selected can be treated as a Map. You may write a POJO for FieldSelect if wanted. FieldSelect has three attrs AppointmentDate, AppointmentDateOrder and ptStatusOrder Commented Nov 5, 2012 at 12:25

1 Answer 1

1

Just map one Json Object as a Java Class. And make an Array of Object as a List..

Like, (pseudo code only)

You are using GSON library so import SerializedName in your pojo classes.

import com.google.gson.annotations.SerializedName;

Pojo Class looks like,

public class Filter {

    @SerializedName("Decription") // This requires same as your Json key 
    public String description;
    @SerializedName("FieldSelected") // The Json Object of FieldSelected
    public Field listDetails;

}

public class Field {
    @SerializedName("ptStatusOrder")
    public int status;
    @SerializedName("AppointmentDateOrder")
    public int dateOrder;
    @SerializedName("AppointmentDate")
    public boolean appDate;
}

And main ListFileter class,

public class ListFilter {

        @SerializedName("Filters") 
        public List<Filter> listFilter;

    }

And in Android code,

Gson gson = new Gson();
ListFilter listFilter = gson.fromJson(jsonResponse, ListFilter.class);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.