我在POJO类中使用@PropertyName
来映射firebase数据。更新到新版本12.0.0
后。报告here后@PropertyName
不再有效了。
更新了POJO课程UserChatGroup.java
Firebase数据架构在这里user_chat_groups-> userIds->列表
GroupItem is here的数据架构
我正在使用ChildEventListener获取所有user_chat_groups
DatabaseReference mDatabaseRef =FirebaseDatabase.getInstance().getReference().child("user_chat_groups").child(userId);
mDatabaseRef.addChildEventListener(childEventListener);
ChildEventListener childEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()) {
try {
//Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
//String groupName = (String) map.get("group_name");
//String careproName = (String) map.get("carepro_name");
UserChatGroup chatGroup = dataSnapshot.getValue(UserChatGroup.class);
chatGroup.setKey(dataSnapshot.getKey());
completionHandler.onSuccess(chatGroup, FirebaseObserverType.CHILD_ADDED);
} catch (Exception e) {
Log.d(TAG, "Exception " + e.getMessage());
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
getValue返回null GroupMember member = dataSnapshot.getValue(GroupMember.class);
当我明确映射Object
时,它可以工作Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
String phone = (String) map.get("phone_number");
String name = (String) map.get("name");
当我尝试通过将所有firebase SDK版本更改为11.2.2
(例如implementation 'com.google.firebase:firebase-database:11.2.2'
时仍然编译为12.0.0