I have collection in firestore which return the response as follows:
{packs=[{subcode=s1, weight=1, price=12}], name=abc, desc=Good, code=001}
How I can create model for this response and parse this data in Android. In the current model, It returns the packs null, I am getting the data desc, name and code but packs is null, packs is a array.
Java code for fetching data:
mFirestore.collection("catend").addSnapshotListener(new EventListener() { @Override public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
if (e != null) {
Log.d(TAG, "onEvent: error" + e.getMessage());
}
for (DocumentChange document : documentSnapshots.getDocumentChanges()) {
switch (document.getType()) {
case ADDED:
ProductTest productModel=document.getDocument().toObject(ProductTest.class);
Log.d(TAG, "onEvent: response"+document.getDocument().getData());
Log.d(TAG, "onEvent: code="+productModel.getCode()); //work
Log.d(TAG, "onEvent: description="+productModel.getDesc()); //work
Log.d(TAG, "onEvent: name="+productModel.getName()); //work
Log.d(TAG, "onEvent: packs"+productModel.getPacksList()); //not work
break;
case REMOVED:
break;
case MODIFIED:
break;
}
}
}
});
Model class:
public class ProductTest {
String code,desc,name;
List<Packs> packs;
public ProductTest() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Packs> getPacksList() {
return packs;
}
public void setPacksList(List<Packs> packsList) {
this.packs = packsList;
}
public class Packs
{
String subcode;
int price;
public String getSubcode() {
return subcode;
}
public void setSubcode(String subcode) {
this.subcode = subcode;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Packs() {
}
}
}
Debug result:
You can see in the images
Firebase structure
Andoird studio log