I'm trying to retreive a custom User
object from Firebase as follows:
getUserFromDB(loggedInUserEmail);
viewModel = new ViewModelProvider(this).get(UserViewModel.class);
viewModel.sendUser(loggedInUser);
//...
public void getUserFromDB(String userEmail) {
DocumentReference docRef = db.collection("users").document(userEmail);
docRef.get().addOnSuccessListener(documentSnapshot -> {
loggedInUser = documentSnapshot.toObject(User.class);
Log.d("User Login", documentSnapshot.getId() + " => " + documentSnapshot.getData());
Toast.makeText(MainActivity.this, "Login successful.", Toast.LENGTH_SHORT).show();
});
}
However, the user being retreived always has null attributes. Here's a screenshot from when I was debugging.
Note: I made sure my User
class has a public empty constructor and all the attributes have a getter method.