I am trying to read from relatime database the following object:
.. to a this Java Category.class:
public class Category {
private String nombre;
private String descripcion;
private String estado;
private List<String> productos;
private List<Page> paginas;
public Category(){}
public Category(String name) {
this.nombre = "";
this.descripcion = "";
this.estado = "";
productos = new ArrayList<>();
paginas = new ArrayList<>();
}
public String getCategoryName() {
return nombre;
}
public void setCategoryName(String nombre) {
this.nombre = nombre;
}
public String getCategoryDescription() {
return descripcion;
}
public void setCategoryDescription(String descripcion) {
this.descripcion = descripcion;
}
public String getCategoryState() {
return estado;
}
public void setCategoryState(String estado) {
this.estado = estado;
}
public List<String> getProducts() {
return this.productos;
}
public void setProducts(List<String> productos) {
this.productos = productos;
}
public List<Page> getPages() {
return this.paginas;
}
public void setPages(List<Page> pages) {
this.paginas = paginas;
}
@Override
public String toString() {
return nombre;
}
}
I have searched and read from different sources and from what I understand I should use Maps, but the truth is, I don't know how to do it ...
This is the code of the reading, and if I debug it, I can see that the dataSnaphot has everything I need, but the Category c is null:
FirebaseDatabase.getInstance().getReference().child("categorias").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Category c = snapshot.getValue(Category.class);
list.add(c);
}
AdapterCategories adapter = new AdapterCategories(list);
recycleView.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
});
This is the JSON exported from FIREBASE:
"categorias" : {
"Telas de Hogar" : {
"descripcion" : "",
"estado" : "invisible",
"nombre" : "Telas de Hogar",
"paginas" : {
"Loneta" : {
"descripcion" : "",
"estado" : "invisible",
"nombre" : "Loneta"
}
}
}
}
Please could anybody help me to solve this problem.