Parse json response android retrofit - android

I am trying to parse response from server in Android studio.
But I am not getting all values in Arraylist.
I have created ItemData.java and ItemResponse.java
I am Calling Api using getItemData Method:
public void getItemData() {
Call<ItemDataResponse> call = service.getData(token, "200");
call.enqueue(new Callback<ItemDataResponse>() {
#Override
public void onResponse(#NonNull Call<ItemDataResponse> call, #NonNull Response<ItemDataResponse> response) {
Log.d("dataFromServer", response.body.toString());
}
#Override
public void onFailure(#NonNull Call<ItemDataResponse> call, #NonNull Throwable t) {
progressDoalog.dismiss();
Toast.makeText(LiveVehiclesActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
This is Json response:
{
"code":"1",
"items":[
{
"item_id":"200",
"speed":"2"
},
{
"item_id":"201",
"speed":"0"
}
]
}
ItemsResponse.java:
public class ItemDataResponse implements Serializable {
#SerializedName("code")
private String code;
#SerializedName("items")
#Expose
private List<ItemData> items;
public String getResponsecode() {
return responsecode;
}
public void setResponsecode(String responsecode) {
this.responsecode = responsecode;
}
public List<ItemData> getItems() {
return items;
}
public void setItems(List<ItemData> items) {
this.items = items;
}
}
ItemData.java
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ItemData {
#SerializedName("item_id")
#Expose
private String itemId;
#SerializedName("speed")
#Expose
private String speed;
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
}
After run in debug mode I am getting response like:
code:"1"
items=null

your should modify
class ItemData {
private String item_id;
private String speed;
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
}

The ItemData model does not seem to be consistent with the JSON response.
i.e
{
"item_id":"200",
"speed":"2"
}
should map to:
class ItemData implements Serializable {
#SerializedName("item_id")
private String itemId;
#SerializedName("speed")
private String speed;
// getters and setters
}

Use SerializedName attribute for the field contains "_". Here for item_id in your ItemData class getting problem in mapping.
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ItemData {
#SerializedName("item_id")
#Expose
private String itemId;
#SerializedName("speed")
#Expose
private String speed;
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
}
please change your ItemDataResponse class also
public class ItemDataResponse {
#SerializedName("code")
#Expose
private String code;
#SerializedName("items")
#Expose
private List<Item> items = null;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}

Related

How to access json array (Android)

I'm creating a weather app using the openweathermap api, and need to access the elements of a json array called "list". It contains the weather forecast for the next several days. I'm using retrofit to parse all the json data as well. Problem is that I cannot access the array at all. I can access the elements of city, however.
json structure
main class
forecast output data
forecast list
forecast item
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.openweathermap.org")
.addConverterFactory(JacksonConverterFactory.create())
.build();
final WeatherService service = retrofit.create(WeatherService.class);
final WeatherForecast forecast = retrofit.create(WeatherForecast.class);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Call<ForecastOutputData> callForecastRequest = forecast.getWeatherInfo(Double.toString(lat), Double.toString(lon), "imperial", "5", "key");
callForecastRequest.enqueue(new Callback<ForecastOutputData>() {
#Override
public void onResponse(Call<ForecastOutputData> forecastCall, Response<ForecastOutputData> forecastResponse) {
ForecastOutputData forecastData = forecastResponse.body();
Log.d("GHEY",forecastData.getCity().getName());
Test.setText("Test " + forecastData.getList);
}
#Override
public void onFailure(Call<ForecastOutputData> call, Throwable t) {
Log.e("mytag", "mymessage",t);
Test.setText("Test FAIL");
}
});
}
});
}
#JsonIgnoreProperties(ignoreUnknown = true)
public class ForecastOutputData {
private int cnt;
private String cod;
private double message;
private List<ForecastList> forecastData;
private City city;
public String getCod() {
return cod;
}
public void setCod(String cod) {
this.cod = cod;
}
public int getCnt() {
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
public List<ForecastList> getForecastData() {
return forecastData;
}
public void setForecastData(List<ForecastList> forecastData) {
this.forecastData = forecastData;
}
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
public double getMessage() {
return message;
}
public void setMessage(double message) {
this.message = message;
}
}
import java.util.List;
class ForecastList {
private int dt;
private Main main;
private List<Weather> weather;
private Clouds clouds;
private Wind wind;
private Sys sys;
private String dtTxt;
public int getDt() {
return dt;
}
public void setDt(int dt) {
this.dt = dt;
}
public Main getMain() {
return main;
}
public void setMain(Main main) {
this.main = main;
}
public Clouds getClouds() {
return clouds;
}
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
public Wind getWind() {
return wind;
}
public void setWind(Wind wind) {
this.wind = wind;
}
public Sys getSys() {
return sys;
}
public void setSys(Sys sys) {
this.sys = sys;
}
public String getDtTxt() {
return dtTxt;
}
public void setDtTxt(String dtTxt) {
this.dtTxt = dtTxt;
}
public List<Weather> getWeather() {
return weather;
}
public void setWeather(List<Weather> weather) {
this.weather = weather;
}
public class ForecastItem {
private String cod;
private double message;
private int cnt;
private List<ForecastList> list;
private City city;
public String getCod() {
return cod;
}
public void setCod(String cod) {
this.cod = cod;
}
public double getMessage() {
return message;
}
public void setMessage(double message) {
this.message = message;
}
public int getCnt() {
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
public List<ForecastList> getList() {
return list;
}
public void setList(List<ForecastList> list) {
this.list = list;
}
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
}
Try it
#JsonIgnoreProperties(ignoreUnknown = true)
class ForecastResponse {
private String cod;
private String message;
private City city;
#JsonProperty("list")
private List<ForecastItem> list;
}
public class ForecastItem {
private int dt;
//dt, main, weather, clouds etc
}

How to get JSON field using GSON and #SerializedName ?

I have an issue with parsing the following JSON object
"paymentCurrency": "eur",
"paymentOptions": [
{
"paymentOptionId": "1CeGuJt2nkxmaMVf",
"paymentProfileUpdateNeeded": false,
"status": "DISABLED",
"supportedCardTypes": [
"CARD_TYPE_1",
"CARD_TYPE_2",
"CARD_TYPE_3"
],
"type": "TYPE_1"
},
{
"paymentOptionId": "J8iAFXRZZC07rJdG",
"status": "DISABLED",
"type": "TYPE_2"
}
],
"tripCost": "3000",
This is what I've tried until now. I cannot use anything besides #SerializedName and GSON to parse the arrays. Please find the model class below :
public class MatchDetails {
//other fields
#SerializedName("paymentOptions")
public ArrayList<PaymentOptionWrapper> options;
}
public class PaymentOptionWrapper {
public PaymentOption option;
}
public class PaymentOption {
#SerializedName("paymentOptionId")
public String paymentOptionId;
#SerializedName("paymentProfileUpdateNeeded")
public boolean profileUpdateNeeded;
#SerializedName("status")
public String status;
#SerializedName("supportedCardTypes")
public ArrayList<String> supportedCards;
#SerializedName("type")
public String type;
}
I have also tried not using a wrapper, mapping the list directly but it is still null.
Try this...
public class MatchDetails {
//other fields
#SerializedName("paymentOptions")
public ArrayList<PaymentOption> options;
public ArrayList<PaymentOption> getOptions() {
return options;
}
public void setOptions(ArrayList<PaymentOption> options) {
this.options = options;
}
}
class PaymentOption {
#SerializedName("paymentOptionId")
public String paymentOptionId;
#SerializedName("paymentProfileUpdateNeeded")
public boolean profileUpdateNeeded;
#SerializedName("status")
public String status;
#SerializedName("supportedCardTypes")
public ArrayList<String> supportedCards;
#SerializedName("type")
public String type;
public String getPaymentOptionId() {
return paymentOptionId;
}
public void setPaymentOptionId(String paymentOptionId) {
this.paymentOptionId = paymentOptionId;
}
public boolean isProfileUpdateNeeded() {
return profileUpdateNeeded;
}
public void setProfileUpdateNeeded(boolean profileUpdateNeeded) {
this.profileUpdateNeeded = profileUpdateNeeded;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public ArrayList<String> getSupportedCards() {
return supportedCards;
}
public void setSupportedCards(ArrayList<String> supportedCards) {
this.supportedCards = supportedCards;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Try this:
public class MatchDetails implements Serializable
{
#SerializedName("paymentOptions")
#Expose
private List<PaymentOption> paymentOptions = null;
private final static long serialVersionUID = 7730239716376724487L;
public List<PaymentOption> getPaymentOptions() {
return paymentOptions;
}
public void setPaymentOptions(List<PaymentOption> paymentOptions) {
this.paymentOptions = paymentOptions;
}
}
and
public class PaymentOption implements Serializable
{
#SerializedName("paymentOptionId")
#Expose
private String paymentOptionId;
#SerializedName("paymentProfileUpdateNeeded")
#Expose
private Boolean paymentProfileUpdateNeeded;
#SerializedName("status")
#Expose
private String status;
#SerializedName("supportedCardTypes")
#Expose
private List<String> supportedCardTypes = null;
#SerializedName("type")
#Expose
private String type;
private final static long serialVersionUID = -5717104877176081166L;
public String getPaymentOptionId() {
return paymentOptionId;
}
public void setPaymentOptionId(String paymentOptionId) {
this.paymentOptionId = paymentOptionId;
}
public Boolean getPaymentProfileUpdateNeeded() {
return paymentProfileUpdateNeeded;
}
public void setPaymentProfileUpdateNeeded(Boolean paymentProfileUpdateNeeded) {
this.paymentProfileUpdateNeeded = paymentProfileUpdateNeeded;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<String> getSupportedCardTypes() {
return supportedCardTypes;
}
public void setSupportedCardTypes(List<String> supportedCardTypes) {
this.supportedCardTypes = supportedCardTypes;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

How to populate recyclerview with compex json data using retrofit?

please advise. I have a complex json object which I get requesting to openweathermap API using Retrofit and GSONConverterFactory. I have a trouble requesting forecast for 5 days, I can't populate my Recyclerview with the data, something goes wrong. I can't get what should I write in the onResponse method of Retrofit callback.
Retrofit requests are all with code 200 and message OK. So trouble is not in this area.
Thank you in advance!
Here is structure of Json object
WeatherData is a root Object which I get parsing my Json, please find the code below. All the code for it (as well as for other POJO's is imported from jsonschema2pojo:
public class WeatherData {
#SerializedName("coord")
#Expose
private Coord coord;
#SerializedName("weather")
#Expose
private List<Weather> weather = null;
#SerializedName("base")
#Expose
private String base;
#SerializedName("main")
#Expose
private Main main;
#SerializedName("visibility")
#Expose
private Integer visibility;
#SerializedName("wind")
#Expose
private Wind wind;
#SerializedName("clouds")
#Expose
private Clouds clouds;
#SerializedName("dt")
#Expose
private Long dt;
#SerializedName("sys")
#Expose
private Sys sys;
#SerializedName("id")
#Expose
private Integer id;
#SerializedName("name")
#Expose
private String name;
#SerializedName("cod")
#Expose
private Integer cod;
public Coord getCoord() {
return coord;
}
public void setCoord(Coord coord) {
this.coord = coord;
}
public List<Weather> getWeather() {
return weather;
}
public void setWeather(List<Weather> weather) {
this.weather = weather;
}
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public Main getMain() {
return main;
}
public void setMain(Main main) {
this.main = main;
}
public Integer getVisibility() {
return visibility;
}
public void setVisibility(Integer visibility) {
this.visibility = visibility;
}
public Wind getWind() {
return wind;
}
public void setWind(Wind wind) {
this.wind = wind;
}
public Clouds getClouds() {
return clouds;
}
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
public Long getDt() {
return dt;
}
public void setDt(Long dt) {
this.dt = dt;
}
public Sys getSys() {
return sys;
}
public void setSys(Sys sys) {
this.sys = sys;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCod() {
return cod;
}
public void setCod(Integer cod) {
this.cod = cod;
}
Here is my RecyclerView.Adapter
public class Forecast5DaysAdapter extends RecyclerView.Adapter<Forecast5DaysAdapter.ForecastHolder> {
List<WeatherData> mWeatherDataList;
public static class ForecastHolder extends RecyclerView.ViewHolder {
public TextView dateOnDate;
public ImageView weatherOnDate;
public TextView tempOnDate;
public TextView windSpeedOnDate;
public ForecastHolder(View view) {
super(view);
dateOnDate = (TextView) view.findViewById(R.id.dateOnDate);
windSpeedOnDate = (TextView) view.findViewById(R.id.windSpeedOnDate);
tempOnDate = (TextView) view.findViewById(R.id.tempOnDate);
weatherOnDate = (ImageView) view.findViewById(R.id.imageOnDate);
}
}
public Forecast5DaysAdapter(List<WeatherData> mWeatherDataList) {
this.mWeatherDataList = mWeatherDataList;
}
#Override
public ForecastHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.forecast_card, parent, false);
final ForecastHolder forecastHolder = new ForecastHolder(view);
return forecastHolder;
}
#Override
public void onBindViewHolder(ForecastHolder holder, int position) {
//FILLING THE CARDS IN RECYCLERVIEW WITH INFORMATION
holder.dateOnDate.setText(mWeatherDataList.get(position).getDt().toString());
holder.tempOnDate.setText(mWeatherDataList.get(position).getMain().getTemp().toString());
holder.windSpeedOnDate.setText(mWeatherDataList.get(position).getWind().getSpeed().toString());
Picasso.with(holder.weatherOnDate.getContext()).load("http://openweathermap.org/img/w/" + mWeatherDataList.get(position).getWeather().get(position).getIcon() + ".png").into(holder.weatherOnDate);
}
#Override
public int getItemCount() {
return 0;
}
Here is the class I want to display the Recyclerview
public class Forecast5Days extends AppCompatActivity {
private static final String API_KEY = "HERE IS THE KEY";
private RecyclerView forecastRecycler;
private ArrayList<WeatherData> mWeatherData;
private Forecast5DaysAdapter forecast5DaysAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forecast_5_days);
forecastRecycler = (RecyclerView) findViewById(R.id.forecast_5_daysRecycler);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
forecastRecycler.setLayoutManager(layoutManager);
final Forecast5DaysAdapter forecast5DaysAdapter = new Forecast5DaysAdapter(mWeatherData);
forecastRecycler.setAdapter(forecast5DaysAdapter);
Intent intent = getIntent();
final String cityName = intent.getStringExtra("cityName");
if (!cityName.isEmpty()) {
Call<WeatherData> call = RetrofitBuilderHelper.weatherAPI.getForecast5Days(cityName, "ru", "metric", API_KEY);
call.enqueue(new Callback<WeatherData>() {
#Override
public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {
//????????????????
}
#Override
public void onFailure(Call<WeatherData> call, Throwable t) {
Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
toast.show();
}
});
} else {
Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with intent", Toast.LENGTH_LONG);
toast.show();
}
}
Your onResponse should be like this
call.enqueue(new Callback<WeatherData>() {
#Override
public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {
if(response.isSuccessful() && response.body != null) {
WeatherData data = response.body();
}
}
#Override
public void onFailure(Call<WeatherData> call, Throwable t) {
Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
toast.show();
}
});
Also your Call is Call<WeatherData> which will give you a single object. If you want a list of objects your call should be Call<List<WeatherData>>
I think you are looking to pass Weatherinstead of WeatherData so your onResponse should look like
call.enqueue(new Callback<WeatherData>() {
#Override
public void onResponse(Call<WeatherData> call, Response<WeatherData> response) {
if(response.isSuccessful() && response.body != null) {
WeatherData data = response.body();
List<Weather> weatherList = data.getWeatherList();
//Pass this list to your adapter
}
}
#Override
public void onFailure(Call<WeatherData> call, Throwable t) {
Toast toast = Toast.makeText(Forecast5Days.this, "Something went wrong with request", Toast.LENGTH_LONG);
toast.show();
}
});
Your JSON return is a List not only a Single WeatherData Object.
So all you should have to do is a cange of the Expected return value.
Try this:
Call<List<WeatherData>> call = RetrofitBuilderHelper.weatherAPI.getForecast5Days(cityName, "ru", "metric", API_KEY);
call.enqueue(new Callback<List<WeatherData>>() {
#Override
public void onResponse(Call<List<WeatherData>> call, Response<List<WeatherData>> response) {
forecastRecycler.weatherList = response.body();
forecastRecycler.notifyDatasetChanged();
}

Default Constructor issue while using Jackson Parser

My model getter setter class looks like this:-
#JsonIgnoreProperties(ignoreUnknown = true)
public class CuratedOffers {
public CuratedOffers() {
}
#JsonProperty("response")
private String response;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
#JsonProperty("data")
private Data mData;
public Data getmData() {
return mData;
}
public void setmData(Data mData) {
this.mData = mData;
}
#JsonIgnoreProperties(ignoreUnknown = true)
public class Data{
#JsonProperty("vendors")
private List<Vendor> vendorList;
public List<Vendor> getVendorList() {
return vendorList;
}
public void setVendorList(List<Vendor> vendorList) {
this.vendorList = vendorList;
}
}
#JsonIgnoreProperties(ignoreUnknown = true)
public static class Vendor {
#JsonProperty("id")
private String Id;
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
#JsonProperty("name")
private String venName;
public String getVenName() {
return venName;
}
public void setVenName(String venName) {
this.venName = venName;
}
#JsonProperty("image")
private String image;
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
#JsonProperty("logo")
private String logo;
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
#JsonProperty("offers")
private String offers;
public String getOffers() {
return offers;
}
public void setOffers(String offers) {
this.offers = offers;
}
#JsonProperty("description")
private String offer_description;
public void setOffer_description(String offer_description) {
this.offer_description = offer_description;
}
public String getOffer_description() {
return offer_description;
}
}
}
And i using Jackson while compiling through gradle ie:-
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.4.2'
After compiling i keep getting this error in my stacktrace
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.yoy.CuratedOffers$Data]: can not instantiate from JSON object (need to add/enable type information?)
Searched SO without any suitable answers.Help would be appreciated!!
As suggested by #vilpel89 i had forgot to declare a static nested class inside CuratedOffers class.Now my updated class is:-
#JsonIgnoreProperties(ignoreUnknown = true)
public class CuratedOffers {
public CuratedOffers() {
}
#JsonProperty("response")
private String response;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
#JsonProperty("data")
private Data mData;
public Data getmData() {
return mData;
}
public void setmData(Data mData) {
this.mData = mData;
}
#JsonIgnoreProperties(ignoreUnknown = true)
public static class Data{
public Data() {
}
#JsonProperty("vendors")
private List<Vendor> vendorList;
public List<Vendor> getVendorList() {
return vendorList;
}
public void setVendorList(List<Vendor> vendorList) {
this.vendorList = vendorList;
}
}
#JsonIgnoreProperties(ignoreUnknown = true)
public static class Vendor {
public Vendor() {
}
#JsonProperty("id")
private String Id;
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
#JsonProperty("name")
private String venName;
public String getVenName() {
return venName;
}
public void setVenName(String venName) {
this.venName = venName;
}
#JsonProperty("image")
private String image;
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
#JsonProperty("logo")
private String logo;
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
#JsonProperty("offers")
private String offers;
public String getOffers() {
return offers;
}
public void setOffers(String offers) {
this.offers = offers;
}
#JsonProperty("description")
private String offer_description;
public void setOffer_description(String offer_description) {
this.offer_description = offer_description;
}
public String getOffer_description() {
return offer_description;
}
}
}
Added a static constructor to my Data class as well as Vendor Class and also added default constructors to it.Now it's working like a charm!Hope it might help someone someday!

RoboSpice-Retrofit POJO

I have a JSON like this:
{"meta": {...}, "objects": [{...}, {...}]}
But the problem is how to construct the POJO class. From the samples there is only one example with simple JSON.
I tried with something like this:
class Test {
public ArrayList<String> meta;
public static class Object {
public String testField;
}
public static class Objects extends ArrayList<Object>{}
}
And in the RetrofitRequest class I use Test.Objects.class
Any help will be appreciated!
I've fixed it with creating classes for meta and object where objects are in ArrayList<Object>
Thanks!
These are the POJO class to hold and parse the json
1)Meta.java
public class Meta {
private int limit;
private String next;
private int offset;
private String previous;
private int total_count;
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public String getNext() {
return next;
}
public void setNext(String next) {
this.next = next;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public String getPrevious() {
return previous;
}
public void setPrevious(String previous) {
this.previous = previous;
}
public int getTotal_count() {
return total_count;
}
public void setTotal_count(int total_count) {
this.total_count = total_count;
}
}
2)Objects.java
public class Objects {
private String description;
private int downloads;
private int family_filter;
private int id;
private String image_url;
private int rating;
private String resource_uri;
private int size;
private String tags;
private String title;
private String uploaded_date;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getDownloads() {
return downloads;
}
public void setDownloads(int downloads) {
this.downloads = downloads;
}
public int getFamily_filter() {
return family_filter;
}
public void setFamily_filter(int family_filter) {
this.family_filter = family_filter;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getImage_url() {
return image_url;
}
public void setImage_url(String image_url) {
this.image_url = image_url;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public String getResource_uri() {
return resource_uri;
}
public void setResource_uri(String resource_uri) {
this.resource_uri = resource_uri;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUploaded_date() {
return uploaded_date;
}
public void setUploaded_date(String uploaded_date) {
this.uploaded_date = uploaded_date;
}
}
3) Finally your Test.java
public class Test {
private Meta meta;
private List<Objects> objects;
public Meta getMeta() {
return meta;
}
public void setMeta(Meta meta) {
this.meta = meta;
}
public List<Objects> getObjects() {
return objects;
}
public void setObjects(List<Objects> objects) {
this.objects = objects;
}
}
Try like this.
This is complete POJO class which will hold the parsed json.

Categories

Resources