0

so I have a list of members (MemberObject) on my Firebase and I'm trying to read them with dataSnapshot.getValue..

The firebase looks like this:

enter image description here

I have MemberObject class looks sort of like this:

public class MemberObject {    
    private String mail;
    private String name;
    ...

And I'm trying to read the whole member list into this:

List<MemberObject> members = dataSnapshot.child("members").getValue(List<MemberObject>.class);

unfortunately this doesn't work as is..

The compiler isn't accepting the List<MemberObject>.class thing.. It says:

Cannot select from parameterized type

What's the right way to do that?

P.S: Just to clear things up, this "members" tree is a leaf under big tree full of "members" leaves so I can't create another addChildEventListener inside every leaf

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Yarden Cohen
  • 584
  • 2
  • 4
  • 19
  • 2
    What you're reading is not a **list** of members. It's a map, from a string key to a member. See http://stackoverflow.com/questions/31137487/retrieving-data-from-firebase – Frank van Puffelen Jun 19 '16 at 22:43
  • Refer to this question. http://stackoverflow.com/questions/30933328/how-to-convert-firebase-data-to-java-object – srijanshukla Jun 19 '16 at 22:44
  • 1
    Thank you for the links, I have also found another solution using getChildren method like this: `for(DataSnapshot member_i : dataSnapshot.child("members").getChildren()) members.add(member_i.getValue(MemberObject.class));` (after I initialize the list using this:) `List members = new ArrayList<>(); ` – Yarden Cohen Jun 20 '16 at 14:09

0 Answers0