Wrapping ResponseEntity into another object - java

I have the following response structure.
{
"URL": "",
"sites": [
{
"details": "",
"details2": "",
"details3": [
{
"moreDetails": "",
"moreDetails2": "",
}
]
},
{
"details": "",
"details2": "",
"details3": [
{
"moreDetails": "",
"moreDetails2": "",
}
]
}
]
}
This is accomplished by having multiple models.
SitesResponse
Sites
Details
MoreDetails
All of them have getter and setters and I just set up the response in the controller. Is there a way to move ALL of the response to a parent object without rewriting the hierarchy?
For an example, something like this:
{
"results": {
"URL": "",
"sites": [
{
"details": "",
"details2": "",
"details3": [
{
"moreDetails": "",
"moreDetails2": ""
}
]
},
{
"details": "",
"details2": "",
"details3": [
{
"moreDetails": "",
"moreDetails2": ""
}
]
}
]
}
}

you have to put them inside another object as below :
Result Model :
#JsonInclude(JsonInclude.Include.NON_NULL)
#JsonPropertyOrder({
"URL",
"sites"
})
public class Results {
#JsonProperty("URL")
private String uRL;
#JsonProperty("sites")
private List < Site > sites = null;
#JsonProperty("URL")
public String getURL() {
return uRL;
}
#JsonProperty("URL")
public void setURL(String uRL) {
this.uRL = uRL;
}
#JsonProperty("sites")
public List < Site > getSites() {
return sites;
}
#JsonProperty("sites")
public void setSites(List < Site > sites) {
this.sites = sites;
}
}
Site Model:
#JsonInclude(JsonInclude.Include.NON_NULL)
#JsonPropertyOrder({
"details",
"details2",
"details3"
})
public class Site {
#JsonProperty("details")
private String details;
#JsonProperty("details2")
private String details2;
#JsonProperty("details3")
private List < Details3 > details3 = null;
#JsonProperty("details")
public String getDetails() {
return details;
}
#JsonProperty("details")
public void setDetails(String details) {
this.details = details;
}
#JsonProperty("details2")
public String getDetails2() {
return details2;
}
#JsonProperty("details2")
public void setDetails2(String details2) {
this.details2 = details2;
}
#JsonProperty("details3")
public List < Details3 > getDetails3() {
return details3;
}
#JsonProperty("details3")
public void setDetails3(List < Details3 > details3) {
this.details3 = details3;
}
Details Model :
#JsonInclude(JsonInclude.Include.NON_NULL)
#JsonPropertyOrder({
"moreDetails",
"moreDetails2"
})
public class Details3 {
#JsonProperty("moreDetails")
private String moreDetails;
#JsonProperty("moreDetails2")
private String moreDetails2;
#JsonProperty("moreDetails")
public String getMoreDetails() {
return moreDetails;
}
#JsonProperty("moreDetails")
public void setMoreDetails(String moreDetails) {
this.moreDetails = moreDetails;
}
#JsonProperty("moreDetails2")
public String getMoreDetails2() {
return moreDetails2;
}
#JsonProperty("moreDetails2")
public void setMoreDetails2(String moreDetails2) {
this.moreDetails2 = moreDetails2;
}
}
Holder Model:
#JsonInclude(JsonInclude.Include.NON_NULL)
#JsonPropertyOrder({
"results"
})
public class Holder {
#JsonProperty("results")
private Results results;
#JsonProperty("results")
public Results getResults() {
return results;
}
#JsonProperty("results")
public void setResults(Results results) {
this.results = results;
}
}
then you can pass the Holder Model as a response

Related

How to handle relative generic types in java?

I'm writing a common abstract class for parsing configs, to adapt different config types, I use generic type to handle this problem, see the following code:
public class Tests {
#Test
public void test() {
TestResponse r = readJsonFile("config.json", TestResponse.class);
System.out.println(r);
}
public static class AbstractResponse<G extends AbstractResponse.BaseGItem<M>, M> {
private List<Item<G, M>> data;
public List<Item<G, M>> getData() {
return this.data;
}
public void setData(List<Item<G, M>> data) {
this.data = data;
}
public static class Item<G extends AbstractResponse.BaseGItem<M>, M> {
private int gId;
private int gGroupId;
private String gTitle;
private String gStyle;
private boolean gUseTab;
private List<G> gItems;
public int getgId() {
return gId;
}
public void setgId(int gId) {
this.gId = gId;
}
public int getgGroupId() {
return gGroupId;
}
public void setgGroupId(int gGroupId) {
this.gGroupId = gGroupId;
}
public String getgTitle() {
return gTitle;
}
public void setgTitle(String gTitle) {
this.gTitle = gTitle;
}
public String getgStyle() {
return gStyle;
}
public void setgStyle(String gStyle) {
this.gStyle = gStyle;
}
public boolean isgUseTab() {
return gUseTab;
}
public void setgUseTab(boolean gUseTab) {
this.gUseTab = gUseTab;
}
public List<G> getgItems() {
return gItems;
}
public void setgItems(List<G> gItems) {
this.gItems = gItems;
}
}
public static class BaseGItem<MItem> {
private int mId;
private int mType;
private String mTitle;
private int mIndex;
private int mTplId;
private List<MItem> mItems;
public int getmId() {
return mId;
}
public int getmType() {
return mType;
}
public String getmTitle() {
return mTitle;
}
public int getmIndex() {
return mIndex;
}
public int getmTplId() {
return mTplId;
}
public List<MItem> getmItems() {
return mItems;
}
}
}
public static class TestResponse
extends AbstractResponse<TestResponse.GItem, TestResponse.MItem> {
public static class GItem extends AbstractResponse.BaseGItem<MItem> {
}
public static class MItem {
private String adMainTitle;
private String adImgUrl;
private String adAppLinkUrl;
public String getAdMainTitle() {
return adMainTitle;
}
public void setAdMainTitle(String adMainTitle) {
this.adMainTitle = adMainTitle;
}
public String getAdImgUrl() {
return adImgUrl;
}
public void setAdImgUrl(String adImgUrl) {
this.adImgUrl = adImgUrl;
}
public String getAdAppLinkUrl() {
return adAppLinkUrl;
}
public void setAdAppLinkUrl(String adAppLinkUrl) {
this.adAppLinkUrl = adAppLinkUrl;
}
}
}
}
When I parse json, I get the following error:
org.codehaus.jackson.map.JsonMappingException: Type variable 'M' can not be resolved (with context of class xxx.Tests$AbstractResponse$Item)
I know in Item class, the generic type G not bind with M, How can I solve this problem??
example config.json:
{
"msg": "success",
"data": [
{
"gStyle": "xxx",
"gId": "100",
"gTitle": "test",
"gItems": [
{
"mItems": [
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
}
],
"mTitle": "",
"mTplId": ""
},
{
"mItems": [
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
},
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
}
]
}
]
},
{
"gStyle": "",
"gId": "90",
"gTitle": "test2",
"gItems": [
{
"mItems": [
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
}
],
"mTitle": "标题",
"mTplId": "2370"
},
{
"mItems": [
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
},
{
"adAppLinkUrl": "",
"adImgUrl": "",
"adMainTitle": ""
}
],
"mTitle": "品类入口",
"mTplId": "2371"
}
]
}
],
"success": true,
"errorCode": 610000
}

Spring Convert enity manager getResultList results to JSON

I'm quite new to spring and I'm using spring entitymanager.createquery to make query and get the result from database.
So when make a http get this method executes to get all the patient name
public List<PatientModel> fetchallpatients (){
Query q = entityManager.createNativeQuery("select * from patient p ");
List <PatientModel> patientList=q.getResultList();
System.out.println(patientList);
return patientList;
}
it is returning
[[
1,
"patientname",
"patientphone",
"patientgender",
"patientinsurance",
"patientage",
"patientdiagnosis",
"patientaddreq",
"patientemr"
],
[
2,
"test",
"patientphone",
"patientgender",
"patientinsurance",
"patientage",
"patientdiagnosis",
"patientaddreq",
"patientemr"
],
[
3,
"react",
"12312",
"male",
"react",
"56",
"dsa",
"ads",
"das"
],
[
4,
"sign",
"asd",
"male",
"react",
"56",
"Diagnose 2",
"Ventilator",
"on"
],
[
5,
"good",
"3213",
"male",
"react",
"56",
"Diagnose 3",
"ICU",
"on"
] ]
Front end I'm using react and I need this data to be in JSON format.
I have a POJO class for corresponding table:
package io.login.model;
import java.io.Serializable;
public class PatientModel {
String patientname;
String patientage;
String patientgender;
String patientinsurance;
String patientphone;
String patientaddreq;
String patientemr;
public String getPatientname() {
return patientname;
}
public void setPatientname(String patientname) {
this.patientname = patientname;
}
public String getPatientage() {
return patientage;
}
public void setPatientage(String patientage) {
this.patientage = patientage;
}
public String getPatientgender() {
return patientgender;
}
public void setPatientgender(String patientgender) {
this.patientgender = patientgender;
}
public String getPatientinsurance() {
return patientinsurance;
}
public void setPatientinsurance(String patientinsurance) {
this.patientinsurance = patientinsurance;
}
public String getPatientphone() {
return patientphone;
}
public void setPatientphone(String patientphone) {
this.patientphone = patientphone;
}
public String getPatientdiagnosis() {
return patientdiagnosis;
}
public void setPatientdiagnosis(String patientdiagnosis) {
this.patientdiagnosis = patientdiagnosis;
}
public String getPatientaddreq() {
return patientaddreq;
}
public void setPatientaddreq(String patientaddreq) {
this.patientaddreq = patientaddreq;
}
public String getPatientemr() {
return patientemr;
}
public void setPatientemr(String patientemr) {
this.patientemr = patientemr;
}
String patientdiagnosis;
public PatientModel(String patientname, String patientage, String patientgender, String patientinsurance, String patientphone, String patientdiagnosis, String patientaddreq, String patientemr) {
this.patientname = patientname;
this.patientage = patientage;
this.patientgender = patientgender;
this.patientinsurance = patientinsurance;
this.patientphone = patientphone;
this.patientdiagnosis = patientdiagnosis;
this.patientaddreq = patientaddreq;
this.patientemr = patientemr;
}
}
But I need the result like
{ { "patientname":"xyz"
"patientphone":"xyz"
"patientinsurance":"xyz"
"patientgender":"xyz"
"patientdiagnosis":"xyz"
"patientaddreq":"xyz" ... so on
}
}
you are returning List<String[]> and expect it to be a JSON list of your POJO?
change your method to return what is expected, like:
#Transactional
public List<PatientModel> fetchallpatients () {
Query q = entityManager.createNativeQuery("select * from patient p ");
List <PatientModel> patientList = q.getResultList();
System.out.println(patientList);
return patientList;
}

Parsing of multiple Arrays in android

Please tell me how i can parse this model, i am a fresher in android. i tried like this way:-
{ "error": false, "response": { "comdata": [{ "id": "35", "address": "Address" }], "empdata": [{ "cid": "33", "comid": "35", "empname": "test", "empdob": "0000-00-00" }, { "cid": "33", "comid": "35", "empname": "test", "empdob": "0000-00-00" }] }
Gson gson = new Gson();
String json = gson.toJson(result);
JSONObject jObj = new JSONObject(json);
if (jObj.getString("error").equalsIgnoreCase("false")) {
JSONObject object = jObj.getJSONObject("response");
for (int i = 0; i < object.length(); i++) {
JSONArray jsonArray = object.getJSONArray("parentdata");
JSONObject jsonObject = jsonArray.getJSONObject(0);
//Something write here
JSONArray jsonArray1 = object.getJSONArray("childata");
for (int a = 0; a < jsonArray1.length(); a++) {
JSONObject object1 = jsonArray1.getJSONObject(a);
} return "true";
}return "true";
}else{
}
Your JSON is invalid correct JSON will look like this.
{
"error": false,
"response": {
"comdata": [
{
"id": "35",
"address": "Address"
}
],
"empdata": [
{
"cid": "33",
"comid": "35",
"empname": "test",
"empdob": "0000-00-00"
},
{
"cid": "33",
"comid": "35",
"empname": "test",
"empdob": "0000-00-00"
}
]
}
}
You can parse the JSON using below code.
private void parseResponse(String result) {
try {
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.getBoolean("error")) {
JSONObject response = jsonObject.getJSONObject("response");
JSONArray jsonArray1 = response.getJSONArray("comdata");
List<ComData> comdataList = new ArrayList<>();
for (int i = 0; i < jsonArray1.length(); i++) {
ComData comData = new ComData();
comData.setId(jsonArray1.getJSONObject(i).getString("id"));
comData.setAddress(jsonArray1.getJSONObject(i).getString("address"));
comdataList.add(comData);
}
JSONArray jsonArray2 = response.getJSONArray("empdata");
List<EmpData> empdataList = new ArrayList<>();
for (int i = 0; i < jsonArray2.length(); i++) {
EmpData empData = new EmpData();
empData.setCid(jsonArray2.getJSONObject(i).getString("cid"));
empData.setComid(jsonArray2.getJSONObject(i).getString("comid"));
empData.setEmpname(jsonArray2.getJSONObject(i).getString("empname"));
empData.setEmpdob(jsonArray2.getJSONObject(i).getString("empdob"));
empdataList.add(empData);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Or you can easily parse JSON to POJO using GSON, refer César Ferreira's answer.
Your JSON is invalid you should have it something like this:
{
"error": false,
"response": {
"comdata": [{
"id": "10",
"username": null,
"email": "example#gmail.com"
}],
"empdata": [{
"eid": "33",
"empname": "test",
"empdob": "0000-00-00",
"empgender": "test",
"empphoto": ""
}],
"someData": [{
"eid": "34",
"empname": "test",
"empdob": "0000-00-00",
"empgender": "test",
"empphoto": ""
}]
}
}
The property someData I had to add it so it would be a valid JSON, I don't know if it fits your requirements.
You can use jsonschematopojo to generate a class like this:
Comdatum class
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Comdatum {
#SerializedName("id")
#Expose
private String id;
#SerializedName("username")
#Expose
private Object username;
#SerializedName("email")
#Expose
private String email;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Object getUsername() {
return username;
}
public void setUsername(Object username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Data class
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Data {
#SerializedName("error")
#Expose
private Boolean error;
#SerializedName("response")
#Expose
private Response response;
public Boolean getError() {
return error;
}
public void setError(Boolean error) {
this.error = error;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response) {
this.response = response;
}
}
Empdatum Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import package com.example;
public class Empdatum {
#SerializedName("eid")
#Expose
private String eid;
#SerializedName("empname")
#Expose
private String empname;
#SerializedName("empdob")
#Expose
private String empdob;
#SerializedName("empgender")
#Expose
private String empgender;
#SerializedName("empphoto")
#Expose
private String empphoto;
public String getEid() {
return eid;
}
public void setEid(String eid) {
this.eid = eid;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public String getEmpdob() {
return empdob;
}
public void setEmpdob(String empdob) {
this.empdob = empdob;
}
public String getEmpgender() {
return empgender;
}
public void setEmpgender(String empgender) {
this.empgender = empgender;
}
public String getEmpphoto() {
return empphoto;
}
public void setEmpphoto(String empphoto) {
this.empphoto = empphoto;
}
}
Response Class
package com.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Response {
#SerializedName("comdata")
#Expose
private List<Comdatum> comdata = null;
#SerializedName("empdata")
#Expose
private List<Empdatum> empdata = null;
#SerializedName("someData")
#Expose
private List<SomeDatum> someData = null;
public List<Comdatum> getComdata() {
return comdata;
}
public void setComdata(List<Comdatum> comdata) {
this.comdata = comdata;
}
public List<Empdatum> getEmpdata() {
return empdata;
}
public void setEmpdata(List<Empdatum> empdata) {
this.empdata = empdata;
}
public List<SomeDatum> getSomeData() {
return someData;
}
public void setSomeData(List<SomeDatum> someData) {
this.someData = someData;
}
}
SomeDatum Class
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class SomeDatum {
#SerializedName("eid")
#Expose
private String eid;
#SerializedName("empname")
#Expose
private String empname;
#SerializedName("empdob")
#Expose
private String empdob;
#SerializedName("empgender")
#Expose
private String empgender;
#SerializedName("empphoto")
#Expose
private String empphoto;
public String getEid() {
return eid;
}
public void setEid(String eid) {
this.eid = eid;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public String getEmpdob() {
return empdob;
}
public void setEmpdob(String empdob) {
this.empdob = empdob;
}
public String getEmpgender() {
return empgender;
}
public void setEmpgender(String empgender) {
this.empgender = empgender;
}
public String getEmpphoto() {
return empphoto;
}
public void setEmpphoto(String empphoto) {
this.empphoto = empphoto;
}
}
And Then you can just do something like this:
String jsonString = "Your JSON String";
Gson converter = new Gson();
Data settingsdata = converter.fromJson(jsonString , Data.class);

retrofit call on object that contains another object represented by an array

I have json data :
[
{
"RouteNo": "004",
"RouteName": "POWELL/DOWNTOWN/UBC",
"Direction": "WEST",
"Schedules": [
{
"Destination": "UBC",
"ExpectedCountdown": -4,
},
{
"Destination": "Downtown",
"ExpectedCountdown": -6,
}
]
},
{
"RouteNo": "006",
"RouteName": "Grange str",
"Direction": "South",
"Schedules": [
{
"Destination": "Victoria",
"ExpectedCountdown": -9,
},
{
"Destination": "College station",
"ExpectedCountdown": -15,
}
]
}
]
And I have my model Route.java:
public class Route {
public String getRouteNo() {
return RouteNo;
}
public void setRouteNo(String routeNo) {
RouteNo = routeNo;
}
public String getRouteName() {
return RouteName;
}
public void setRouteName(String routeName) {
RouteName = routeName;
}
public Route(String routeNo, String routeName) {
RouteNo = routeNo;
RouteName = routeName;
}
private String RouteNo;
private String RouteName;
}
My question is how should I insert Schedules object you can see in json data into Route model? I am confused in terms of (as far as I understood) it is an object containing an array and I am not sure how to represent it in this case. And how actually get the data from it in retrofit call? I need to get each destination for each route.
Update Route to be:
public class Route {
public String getRouteNo() {
return RouteNo;
}
public void setRouteNo(String routeNo) {
RouteNo = routeNo;
}
public String getRouteName() {
return RouteName;
}
public void setRouteName(String routeName) {
RouteName = routeName;
}
public Route(String routeNo, String routeName) {
RouteNo = routeNo;
RouteName = routeName;
}
private String RouteNo;
private String RouteName;
private List<Schedule> schedules; // add mutators with #JsonProperty annotation
}
Then create the Schedule class as described by the above JSON

how to parse local Json Dynamically for fixed pojo class using fasterxml jackson in android java

Here is a json file.
{
"RackItems": [
{
"Name": "Profile",
"Description": "Profile Items",
"MainContentItems": [
{
"Name": "Personal",
"Description": "Profile",
"ContentItems": [
{
"Name": "Personal Details",
"Type": "Profile"
}
]
},
{
"Name": "My Playlists",
"Description": "Playlists",
"ContentItems": [
{
"Name": "My Playlists",
"Description": "My Playlists",
"Type": "Playlist"
}
]
}
]
},
{
"Name": "Home",
"Description": "Home Items",
"ContentItems": [
{
"Name": "Top Songs",
"Description": "Top Songs",
"Type": "Song"
},
{
"Name": "Top Albums",
"Description": "Top Albums",
"Type": "Album"
}
]
}
],
"DetailedItems": {
"Genre": {
"Name": "Genre",
"Description": "Genre Items",
"ContentItems": [
{
"Name": "Top ## Songs",
"Description": "Top Songs"
},
{
"Name": "Top ## Albums",
"Description": "Top Albums"
}
]
},
"UserProfile": {
"Name": "User Profile",
"Description": "User Profile",
"MainContentItems": [
{
"Name": "Personal",
"Description": "Profile",
"ContentItems": [
{
"Name": "Personal Details",
"Description": "Personal Details",
"ItemType": "ProfileView"
}
]
},
{
"Name": "Playlists",
"Description": "Playlists",
"ContentItems": [
{
"Name": "Playlists",
"Description": "Playlists",
"ItemType": "Playlist"
}
]
}
]
}
},
"DownloadSongs": {
"Name": "Download Songs",
"Description": "Download Songs",
"ItemType": "DownloadSongsResult"
}
}
And here are individual pojo class:
#JsonIgnoreProperties(ignoreUnknown = true)
public class ContentMusicPlayerChild {
String Name, Description;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
}
and other pojo with same type of getter setter with top class
List<Object> cStringList = new ArrayList<>();
#JsonAnyGetter
public List<Object> getcStringList() {
return cStringList;
}
#JsonAnySetter
public void setcStringList(List<Object> cStringList) {
this.cStringList = cStringList;
}
Here I used JsonAnyGetter and JsonAnySetter to get any data that contains. Like
ContentMusicPlayer contentMusicPlayer = null;
ObjectMapper objectMapper = new ObjectMapper();
contentMusicPlayer = objectMapper.readValue(UtilMethod.loadJSONFromAsset(context), ContentMusicPlayer.class);
Log.e("contentMusicPlayer", contentMusicPlayer+ "");
return contentMusicPlayer;
But it returns me null. where am I missing. Those can be done like
#JsonProperty("DetailedItems")
private DetailedItems DetailedItems;
#JsonProperty("SimilarArtists")
private SimilarArtists SimilarArtists;
#JsonProperty("RackItems")
private List<RackItems> RackItems;
But I dont want to make hard code pojos but flexible as per changeable in future.
//Main parser class
public class MainParser {
RackItemsData RackItems;
GenereData DetailedItems;
public DownloadSongsData getDownloadSongs() {
return DownloadSongs;
}
public void setDownloadSongs(DownloadSongsData downloadSongs) {
DownloadSongs = downloadSongs;
}
public GenereData getDetailedItems() {
return DetailedItems;
}
public void setDetailedItems(GenereData detailedItems) {
DetailedItems = detailedItems;
}
public RackItemsData getRackItems() {
return RackItems;
}
public void setRackItems(RackItemsData rackItems) {
RackItems = rackItems;
}
DownloadSongsData DownloadSongs;
}
// Second class
public class RackItemsData {
String Name;
String Description;
ArrayList<MainContentItemsData> MainContentItems;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public ArrayList<MainContentItemsData> getMainContentItems() {
return MainContentItems;
}
public void setMainContentItems(ArrayList<MainContentItemsData> mainContentItems) {
MainContentItems = mainContentItems;
}
}
//ThirdClass
public class MainContentItemsData {
String Name;
String Description;
ArrayList<ContentItemsData> ContentItems;
public ArrayList<ContentItemsData> getContentItems() {
return ContentItems;
}
public void setContentItems(ArrayList<ContentItemsData> contentItems) {
ContentItems = contentItems;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
}
//Forth class
public class ContentItemsData {
String Name;
String Description;
String Type;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
}
}
//Fifth Class
public class GenereData {
MainContentItemsData Genre;
public MainContentItemsData getGenre() {
return Genre;
}
public void setGenre(MainContentItemsData genre) {
Genre = genre;
}
public RackItemsData getUserProfile() {
return UserProfile;
}
public void setUserProfile(RackItemsData userProfile) {
UserProfile = userProfile;
}
RackItemsData UserProfile;
}
//Sixth class
public class DownloadSongsData {
String Name;
String Description;
String ItemType;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getItemType() {
return ItemType;
}
public void setItemType(String itemType) {
ItemType = itemType;
}
}
/////
use GSon libraru and parse data;
Gson gson = new Gson();
MainParser resultObject = gson.fromJson(jsonResultString, MainParser.class);

Categories

Resources