[java] Firebase中的用戶組


Answers

Question

User被定義為:

public class User {
  private String email;
  private String uid;
  private List<Group> groups;

  public User(String email, String uid) {
    this.email = email;
    this.uid = uid;
    this.groups = new ArrayList<>();
  }

  public User() {}

  public User(String email, String uid, ArrayList<Group> groups) {
    this.email = email;
    this.uid = uid;
    this.groups = groups;
  }

  public String getEmail() {
    return email;
  }

  public String getUid() {
    return uid;
  }

  public List<Group> getGroups() {
    return groups;
  }

  public void addGroup(Group group) {
    if (this.groups == null) {
      this.groups = new ArrayList<>();
    }
    this.groups.add(group);
  }
}

Group被定義為:

public class Group {
  private List<User> memberList;

  private Group() {
  }

  public Group(List<User> users) {
    this.memberList = users;
  }

  public void addMember(User member) {
    this.memberList.add(member);
  }

  public List<User> getMemberList() {
    return memberList;
  }
}

嘗試保存到firebase時,會產生以下運行時錯誤:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException
                                                                             at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:611)

問題在於循環引用,還是Firebase無法以這種方式存儲數據?




Links