mardi 22 novembre 2016

Firebase query hashmap to class

I'm using firebase, and I'm doing some query to get the data, and then I'm using addChildEventListener I also tried addValueEventListenerto get the result . The response from dataSnapshot.getValue() is a HashMap.

I found that each key in that HashMap (in first case) represents the field in my class.

Is there a faster way to convert that HashMap to my class\model? or do I have to do it custom for each class I have?. I found in LINK that I can use dataSnapshot.getValue(User.class);, however, it throws DataseException.

My experience with reflection is very little, but I understand in theory I can use it, but not sure how, so if possible an example would appreciated.

Thanks.





Aucun commentaire:

Enregistrer un commentaire