user3145236
user3145236

Reputation: 11

Issues Saving Objects to Firebase Realtime Database

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;
    }

}

Upvotes: 0

Views: 971

Answers (1)

user3145236
user3145236

Reputation: 11

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.

Upvotes: 1

Related Questions