Is it possible to write a nested structure into firebase realtime db?
In my case I want to write a user to DB which have a reference to a Socks object which have String properties. In the db I need a child called "SocksCards" with childs with its properties. With this sample code the socksCard object is ignored, the user data is updated.
public void onDataChange(@NonNull DataSnapshot snapshot) {
User user = snapshot.getValue(User.class);
user.addSocksCards(socks);
userDb.setValue(user);
}
public class User {
public String username, surname, firstName, email, id, gender;
private SocksCard socksCards;
public User(){
}
public User(String username, String surname, String firstName, String email, String id, String gender){
this.username = username;
this.surname = surname;
this.firstName = firstName;
this.email = email;
this.id = id;
this.gender = gender;
}
public void addSocksCards(SocksCard sc){
this.socksCards = sc;
}
}
public class SocksCard {
private String socksID;
public SocksCard(String socksID){
this.socksID = socksID;
}
public String getSocksID() {
return socksID;
}
}