Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中轻松检索聊天应用程序的嵌套firebase实时数据库数据?_Java_Firebase_Firebase Realtime Database_Chat - Fatal编程技术网

如何在java中轻松检索聊天应用程序的嵌套firebase实时数据库数据?

如何在java中轻松检索聊天应用程序的嵌套firebase实时数据库数据?,java,firebase,firebase-realtime-database,chat,Java,Firebase,Firebase Realtime Database,Chat,我正在编写一个聊天应用程序,我需要在其中检查两个用户u1和u2是否有以前的对话。如果有,则检索conversationId并向该端点发送消息。否则,创建一个新的对话 我的数据结构看起来像这样 userconversations: userId1: conversationID1: participants: user1: true user2: true conver

我正在编写一个聊天应用程序,我需要在其中检查两个用户u1和u2是否有以前的对话。如果有,则检索conversationId并向该端点发送消息。否则,创建一个新的对话

我的数据结构看起来像这样

userconversations:
    userId1:
        conversationID1:
            participants:
                user1: true
                user2: true
         conversationID2:
             participants:
                user1: true
                user7: true
在我的应用程序中,我想读取userconversations/userId1中的所有数据,并遍历列表,以确定user2是否是会话的一部分

我的问题是如何设计类,以便快速反序列化这些数据并避免使用getChildren调用对其进行迭代

如果我规范化数据并保持不同的conversationId->参与者映射,那么对于每个conversationId,我必须查询该流以获取数据。如果一个用户可以有100次对话,那么这将是非常缓慢和资源密集的


请随意建议替代方案设计,以解决我的问题。

由于密钥user1、user2和user7是动态的,它们不能自动序列化为POJO的属性。您最好使用GenericTypeIndicator或cast:Mapsnapshot.ChildParticients.getValue从参与者那里获取地图。

Hi Frank。谢谢你的回答。我会试试这个。