User group in firebase

A User is defined as:

 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 defined as:

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

When trying to save to firebase this gives a runtime error:

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

Is the problem related to circular references or cannot Firebase store data this way?

+8
java android firebase firebase-database
source share
1 answer

Yes, I think the problem is with the Circular Link. Where there is a circular link, there is always a problem with its serialization.

As we can see, you have a two-way relationship between users and groups. According to the official documentation, you can improve the structure as:

 { "users": { "user1": { "name": "User 1", "groups": { "group1": true, "group2": true, "group3": true }, "user2": { "name": "User 2", "groups": { "group2": true, "group3": true } }, ... }, "groups": { "group1": { "name": "Group 1", "members": { "user1": true }, "group2": { "name": "Group 2", "members": { "user1": true, "user2": true }, "group3": { "name": "Group 3", "members": { "user1": true, "user2": true } }, ... } } 
+6
source share

All Articles