0

Working on saving user objects to my Firebase Database, but cannot seem to save any complex custom objects.

protected DatabaseReference userRef =  FirebaseDatabase.getInstance().getReference().child("users");
/.../   
User user = new User();
User.setGroups(new ArrayList<String>());
User.setCurrentlyReading(new ArrayList<String>());
userRef.child(userId).setValue(user);

I can save data when I swap out the user in setValue with a string, so I know at least my connection works and I can at least write something to the database.

Any help would be much appreciated.

Update: Adding details on user object

@IgnoreExtraProperties
public class User {

    private List<String> groups;
    private List<String> currentlyReading;

    public User(){}


    public List<String> getGroups() {
        return books;
    }

    public void setGroups(List<String> groups) {
        this.groups = groups;
    }

    public List<String> getCurrentlyReading() {
        return currentlyReading;
    }

    public void setCurrentlyReading(List<String> currentlyReading) {
        this.currentlyReading = currentlyReading;
    }

}
2

1 Answer 1

1

Ah, finally found the issue. Firebase doesn't like empty objects. Added the userId to the user object and that finally saved it into my database.

Not the answer you're looking for? Browse other questions tagged or ask your own question.