I am inquiring if it is possible to generate a model class from a Firestore document snapshot or retrieve and bind field values to views from a document snapshot without having a model class or with a model class that has fewer objects compared to the fields in the Firestore document.
For example in this code got from the documentation:
public static class Post {
public String author;
public String title;
public Post(String author, String title) {
// ...
}
}
// Get a reference to our posts
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("server/saving-data/fireblog/posts");
// Attach a listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Post post = dataSnapshot.getValue(Post.class);
System.out.println(post);
}
We expect the document to have 2 fields. But suppose it has more than two fields that were not declared in the model class. How would one retrieve the values of those other fields and bind them to views in Android?