I used to parse dataSnapshots using maps like this Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
But then when I was watching a tutorial on YouTube I saw the guy parsing the dataSnapshot using a class like this User user = dataSnapshot.getValue(User.class);
and now I have a lot of questions.
How does that work?
I mean what if the class User had different members than the snapshot would it give us an error?
For example
snapshot:
-User
|-Name:jojo
|-Age:19
User Class fields:
boolean a;
float x;
int c;
what if the fields of the class User where putter in a different order than the ones on the snapshot and with different capitalization or what if the class had one missing field?
Example for my second question:
snapshot:
-User
|-Name:jojo
|-Age:19
User Class fields:
int age;
String name;
I have read the firebase docs https://firebase.google.com/docs/reference/android/com/google/firebase/database/DataSnapshot#getValue(java.lang.Class) but it does not answer my two questions it just says the class must have an empty constructor and a getter for each field
EDIT:
snapshot:
-User
|-Followers
|-id:xxxxxx
|-id:xxxxxx
|-Name:jojo
|-Age:19
User Class fields:
int age;
String name;