I'm trying to pair objects JSON with GSON I'm used to knowing the names of the objects, I create the classes and I just have to call those classes to use the objects and build custom adapters and finally fill lists or other views easily with GSON.
In this example I do not know the names of the JSON objects since they are quite random and it is not practical to create classes with those names besides that there is not a certain amount of objects, that is, it can be only 1 or More than 10 for example, is there any way in which you can create a java class that contains the information of the objects and can create lists or other views using or calling that class without knowing the names?
I've read in Stackoverflow something about HashMap or Map as well as Gson deserealizer customized but I'm not familiar with it, is it possible to use GSON or should I implement some other logic ?, Thanks in advance, I leave the example of the JSON, the question is in the object "items" as you can notice is not known the amount and the name of the object because they are random, this is for Android:
[
{
"id": 1001,
"name": "Super1",
"user": {
"character": "The Super 1"
},
"items": {
"987987M7812b123": {
"id": 1,
"strong": 456,
"active": true,
"set": "tier1"
},
"90812bn120893": {
"id": 2,
"strong": 4700,
"active": true,
"set": "vex"
},
"981273jn19203nj": {
"id": 3,
"strong": 3000,
"active": true,
"set": "nesp"
}
}
}
]
I add the code of the class where I implement GSON:
import com.google.gson.annotations.SerializedName;
public class test_de {
private int id;
private String name;
private UserBean user;
private ItemsBean items;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}
public ItemsBean getItems() {
return items;
}
public void setItems(ItemsBean items) {
this.items = items;
}
public static class UserBean {
/**
* character : The Super 1
*/
private String character;
public String getCharacter() {
return character;
}
public void setCharacter(String character) {
this.character = character;
}
}
public static class ItemsBean {
/**
* 987987M7812b123 : {"id":1,"strong":456,"active":true,"set":"tier1"}
* 90812bn120893 : {"id":2,"strong":4700,"active":true,"set":"vex"}
* 981273jn19203nj : {"id":3,"strong":3000,"active":true,"set":"nesp"}
*/
@SerializedName("987987M7812b123")
private _$987987M7812b123Bean _$987987M7812b123;
@SerializedName("90812bn120893")
private _$90812bn120893Bean _$90812bn120893;
@SerializedName("981273jn19203nj")
private _$981273jn19203njBean _$981273jn19203nj;
public _$987987M7812b123Bean get_$987987M7812b123() {
return _$987987M7812b123;
}
public void set_$987987M7812b123(_$987987M7812b123Bean _$987987M7812b123) {
this._$987987M7812b123 = _$987987M7812b123;
}
public _$90812bn120893Bean get_$90812bn120893() {
return _$90812bn120893;
}
public void set_$90812bn120893(_$90812bn120893Bean _$90812bn120893) {
this._$90812bn120893 = _$90812bn120893;
}
public _$981273jn19203njBean get_$981273jn19203nj() {
return _$981273jn19203nj;
}
public void set_$981273jn19203nj(_$981273jn19203njBean _$981273jn19203nj) {
this._$981273jn19203nj = _$981273jn19203nj;
}
public static class _$987987M7812b123Bean {
/**
* id : 1
* strong : 456
* active : true
* set : tier1
*/
private int id;
private int strong;
private boolean active;
private String set;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getStrong() {
return strong;
}
public void setStrong(int strong) {
this.strong = strong;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getSet() {
return set;
}
public void setSet(String set) {
this.set = set;
}
}
public static class _$90812bn120893Bean {
/**
* id : 2
* strong : 4700
* active : true
* set : vex
*/
private int id;
private int strong;
private boolean active;
private String set;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getStrong() {
return strong;
}
public void setStrong(int strong) {
this.strong = strong;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getSet() {
return set;
}
public void setSet(String set) {
this.set = set;
}
}
public static class _$981273jn19203njBean {
/**
* id : 3
* strong : 3000
* active : true
* set : nesp
*/
private int id;
private int strong;
private boolean active;
private String set;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getStrong() {
return strong;
}
public void setStrong(int strong) {
this.strong = strong;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getSet() {
return set;
}
public void setSet(String set) {
this.set = set;
}
}
}}