ArrayList的Firebase数据库事务MutableData

时间:2018-07-09 22:47:48

标签: java android firebase firebase-realtime-database

当前尝试从Firebase实时数据库中的MutableData获取Java对象的ArrayList。但是,我收到null,我不确定是否正确传递了class参数。我目前使用的类参数为ArrayList.class,但我认为它不能处理其中的自定义Java对象。

  public Transaction.Result doTransaction(MutableData mutableData) {
            ArrayList<Friend> friends = mutableData.getValue(ArrayList.class);
            if (friends != null) {
                User.getInstance().setFriendList(friends);
                return Transaction.success(mutableData);
            } else {
                Log.e("DAO", "Failed to load user friends list.");
                User.getInstance().setFriendList(new ArrayList<>());
                return Transaction.abort();
            }

        }

这是朋友pojo:

public class Friend {

public Friend(String displayName, String uid){
    this.name = displayName;
    this.uid = uid;
}

private String name;

public String getUID() {
    return uid;
}

public void setUID(String uid) {
    this.uid = uid;
}

private String uid;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

0 个答案:

没有答案