Android “转换Firebase存储”;数组";对象到POJO

Android “转换Firebase存储”;数组";对象到POJO,android,firebase,android-recyclerview,firebase-realtime-database,Android,Firebase,Android Recyclerview,Firebase Realtime Database,我正在尝试在android应用程序的recyclerview中从firebase检索数据。我正在引用的“boardz”节点上的对象有两个子属性。这些属性都有多个子属性 使用Firebase json和pojo更新: { "game" : { "boardz" : { "-KTaL6V06e3SkEAvfU_3" : { "hostData" : { "hostId" : "MUC6gtRqInRQmqxe7khlmrAbjVZ2", "ownerAddress

我正在尝试在android应用程序的recyclerview中从firebase检索数据。我正在引用的“boardz”节点上的对象有两个子属性。这些属性都有多个子属性

使用Firebase json和pojo更新:

{
"game" : {
"boardz" : {
  "-KTaL6V06e3SkEAvfU_3" : {
    "hostData" : {
      "hostId" : "MUC6gtRqInRQmqxe7khlmrAbjVZ2",
      "ownerAddress" : "n3b9t3vDR6Yiot4HwxwZoa7vxZBiAKReeH",
      "secretString" : "derp-a-derp"
    },
    "metadata" : {
      "across" : [ 2, 0, 5, 9, 7, 8, 1, 4, 3, 6 ],
      "awayTeam" : "ATL",
      "boardFeeBTC" : "",
      "boardFeeUSD" : 14,
      "collectionAddress" : "2NEPnGPyvy9F5N4W4CjhLNPZLwTFNSAzjAL",
      "down" : [ 1, 6, 8, 7, 3, 5, 2, 0, 9, 4 ],
      "endTime" : "2016-10-09T22:09:39.807Z",
      "homeTeam" : "DEN",
      "q1AwayScore" : "",
      "q1HomeScore" : "",
      "q1WinnerAddress" : "",
      "q2AwayScore" : "",
      "q2HomeScore" : "",
      "q2WinnerAddress" : "",
      "q3AwayScore" : "",
      "q3HomeScore" : "",
      "q3WinnerAddress" : "",
      "q4AwayScore" : "",
      "q4HomeScore" : "",
      "q4WinnerAddress" : "",
      "startTime" : "2016-10-08T22:09:39.807Z",
      "winnersPaid" : false
    }
  },
  "-KTaP0-GPSCwCDA8BUlt" : {
    "hostData" : {
      "hostId" : "MUC6gtRqInRQmqxe7khlmrAbjVZ2",
      "ownerAddress" : "mtLF8hks46i9DbSK1tBpenYMDsHpTbnuwC",
      "secretString" : "do-diddly-doo"
    },
    "metadata" : {
      "across" : [ 9, 1, 6, 8, 0, 2, 4, 7, 3, 5 ],
      "awayTeam" : "BUF",
      "boardFeeBTC" : "",
      "boardFeeUSD" : 25,
      "collectionAddress" : "2N5VgMfKwCtJaiT4CLVAMvMQUG6PTbreY4z",
      "down" : [ 9, 2, 4, 3, 7, 0, 5, 6, 8, 1 ],
      "endTime" : "2016-10-09T22:26:47.467Z",
      "homeTeam" : "LA",
      "q1AwayScore" : "",
      "q1HomeScore" : "",
      "q1WinnerAddress" : "",
      "q2AwayScore" : "",
      "q2HomeScore" : "",
      "q2WinnerAddress" : "",
      "q3AwayScore" : "",
      "q3HomeScore" : "",
      "q3WinnerAddress" : "",
      "q4AwayScore" : "",
      "q4HomeScore" : "",
      "q4WinnerAddress" : "",
      "startTime" : "2016-10-08T22:26:47.467Z",
      "winnersPaid" : false
    }
  }
},
我用了这个答案 创建pojo以检索嵌套数据,并且类部分工作

我的问题是答案没有解释如何从数据库检索数组数据。(不是对象列表,只是带整数的普通数组数据)child2 pojo没有使用firebase中的数据填充

hostData pojo已成功映射到firebase子节点。hostData的所有属性都是字符串,因此我认为这使得匹配变得很容易

元数据的第一个属性是数组

如前所述,我知道firebase将数组存储为json对象。我需要将这些“数组”对象转换为java列表或ArrayList,以便填充元数据的pojo

那么,如何将存储在firebase节点中的阵列数据表示为pojo呢

我添加了pojo以帮助查看如何创建对象和映射属性。也许我错过了什么

public class Board {

private HostData hostData;//this class maps to the firebase json
private MetaData metaData;//this class isn't mapping to any of the json properties.

public Board() {
}

public Board(HostData hostData, MetaData metaData) {
    this.hostData = hostData;
    this.metaData = metaData;
}

public HostData getHostData() {
    return hostData;
}

public MetaData getMetaData() {
    return metaData;
}
//the hostData class works fine
public static class HostData {

    private String hostId;
    private String ownerAddress;
    private String secretString;

    public HostData() {
    }

    public HostData(String hostId, String ownerAddress, String secretString) {
        this.hostId = hostId;
        this.ownerAddress = ownerAddress;
        this.secretString = secretString;
    }

    public String getHostId() {
        return hostId;
    }

    public String getOwnerAddress() {
        return ownerAddress;
    }

    public String getSecretString() {
        return secretString;
    }
}
//this class is giving me hell. Am I missing something?
public static class MetaData {

    private List<Long> across = new ArrayList<>();
    private String awayTeam;
    private Double boardFeeBTC;
    private Double boardFeeUSD;
    private String collectionAddress;
    private List<Long> down = new ArrayList<>();
    private String endTime;
    private String homeTeam;
    private Long q1AwayScore;
    private Long q1HomeScore;
    private String q1WinnerAddress;
    private Long q2AwayScore;
    private Long q2HomeScore;
    private String q2WinnerAddress;
    private Long q3AwayScore;
    private Long q3HomeScore;
    private String q3WinnerAddress;
    private Long q4AwayScore;
    private Long q4HomeScore;
    private String q4WinnerAddress;
    private String startTime;
    private Boolean winnersPaid;

    public MetaData() {
    }

    public MetaData(List<Long> across, String awayTeam, Double boardFeeBTC, Double boardFeeUSD, String collectionAddress, List<Long> down, String endTime, String homeTeam, Long q1AwayScore, Long q1HomeScore, String q1WinnerAddress, Long q2AwayScore, Long q2HomeScore, String q2WinnerAddress, Long q3AwayScore, Long q3HomeScore, String q3WinnerAddress, Long q4AwayScore, Long q4HomeScore, String q4WinnerAddress, String startTime, Boolean winnersPaid) {
        this.across = across;
        this.awayTeam = awayTeam;
        this.boardFeeBTC = boardFeeBTC;
        this.boardFeeUSD = boardFeeUSD;
        this.collectionAddress = collectionAddress;
        this.down = down;
        this.endTime = endTime;
        this.homeTeam = homeTeam;
        this.q1AwayScore = q1AwayScore;
        this.q1HomeScore = q1HomeScore;
        this.q1WinnerAddress = q1WinnerAddress;
        this.q2AwayScore = q2AwayScore;
        this.q2HomeScore = q2HomeScore;
        this.q2WinnerAddress = q2WinnerAddress;
        this.q3AwayScore = q3AwayScore;
        this.q3HomeScore = q3HomeScore;
        this.q3WinnerAddress = q3WinnerAddress;
        this.q4AwayScore = q4AwayScore;
        this.q4HomeScore = q4HomeScore;
        this.q4WinnerAddress = q4WinnerAddress;
        this.startTime = startTime;
        this.winnersPaid = winnersPaid;
    }

    public List<Long> getAcross() {
        return across;
    }

    public String getAwayTeam() {
        return awayTeam;
    }

    public Double getBoardFeeBTC() {
        return boardFeeBTC;
    }

    public Double getBoardFeeUSD() {
        return boardFeeUSD;
    }

    public String getCollectionAddress() {
        return collectionAddress;
    }

    public List<Long> getDown() {
        return down;
    }

    public String getEndTime() {
        return endTime;
    }

    public String getHomeTeam() {
        return homeTeam;
    }

    public Long getQ1AwayScore() {
        return q1AwayScore;
    }

    public Long getQ1HomeScore() {
        return q1HomeScore;
    }

    public String getQ1WinnerAddress() {
        return q1WinnerAddress;
    }

    public Long getQ2AwayScore() {
        return q2AwayScore;
    }

    public Long getQ2HomeScore() {
        return q2HomeScore;
    }

    public String getQ2WinnerAddress() {
        return q2WinnerAddress;
    }

    public Long getQ3AwayScore() {
        return q3AwayScore;
    }

    public Long getQ3HomeScore() {
        return q3HomeScore;
    }

    public String getQ3WinnerAddress() {
        return q3WinnerAddress;
    }

    public Long getQ4AwayScore() {
        return q4AwayScore;
    }

    public Long getQ4HomeScore() {
        return q4HomeScore;
    }

    public String getQ4WinnerAddress() {
        return q4WinnerAddress;
    }

    public String getStartTime() {
        return startTime;
    }

    public Boolean getWinnersPaid() {
        return winnersPaid;
    }
}
}
公共课程委员会{
private HostData HostData;//此类映射到firebase json
私有元数据;//此类未映射到任何json属性。
公共委员会(){
}
公共板(主机数据主机数据元数据){
this.hostData=hostData;
this.metaData=元数据;
}
公共HostData getHostData(){
返回主机数据;
}
公共元数据getMetaData(){
返回元数据;
}
//hostData类工作正常
公共静态类主机数据{
私有字符串hostId;
私有字符串所有者地址;
私密字符串;
公共主机数据(){
}
公共主机数据(字符串hostId、字符串ownerAddress、字符串secretString){
this.hostId=hostId;
this.ownerAddress=ownerAddress;
this.secretString=secretString;
}
公共字符串getHostId(){
返回hostId;
}
公共字符串getOwnerAddress(){
返回所有者地址;
}
公共字符串getSecretString(){
返回secretString;
}
}
//这门课真让我受不了。我是不是错过了什么?
公共静态类元数据{
private List overs=new ArrayList();
私人字符串awayTeam;
私人双董事会;
私人双董事会;美元;
私有字符串收集地址;
private List down=new ArrayList();
私有字符串结束时间;
私人弦乐队;
私人长轴;
私人长桩;
私有字符串地址;
私人长途电话;
私人长桩;
私有字符串地址;
私人长轴;
私人长线核心;
私有字符串地址;
私人长途电话;
私人长线核心;
私有字符串地址;
私有字符串开始时间;
私人付费电话;
公共元数据(){
}
公共元数据(跨列、串AwayTam、双板FeeBTC、双板FeEUSD、串收集地址、下拉列表、串结束时间、串homeTeam、长q1AwayScore、长Q1 HomeScore、长q1WinnerAddress、长q2AwayScore、长q2WinnerAddress、长q3AwayScore、长q3WinnerAddress、长q4HomeScore,字符串q4WinnerAddress,字符串startTime,布尔winnersPaid){
这个;
this.awayTeam=awayTeam;
this.boardFeeBTC=boardFeeBTC;
this.boardFeeUSD=boardFeeUSD;
this.collectionAddress=collectionAddress;
this.down=向下;
this.endTime=endTime;
this.homeTeam=homeTeam;
this.q1AwayScore=q1AwayScore;
this.q1HomeScore=q1HomeScore;
this.q1WinnerAddress=q1WinnerAddress;
this.q2AwayScore=q2AwayScore;
this.q2HomeScore=q2HomeScore;
this.q2WinnerAddress=q2WinnerAddress;
this.q3AwayScore=q3AwayScore;
this.q3HomeScore=q3HomeScore;
this.q3WinnerAddress=q3WinnerAddress;
this.q4AwayScore=q4AwayScore;
this.q4HomeScore=q4HomeScore;
this.q4WinnerAddress=q4WinnerAddress;
this.startTime=startTime;
this.winnersPaid=winnersPaid;
}
公共列表getovers(){
回过头来;
}
公共字符串getAwayTeam(){
返回阿瓦泰姆;
}
公共双getBoardFeeBTC(){
返回boardFeeBTC;
}
公共双卡(美元){
返回美元;
}
公共字符串getCollectionAddress(){
返回收集地址;
}
公共列表getDown(){
返回下来;
}
公共字符串getEndTime(){
返回结束时间;
}
公共字符串getHomeTeam(){
返回主队;
}
公共长时间getQ1AwayScore(){
返回q1AwayScore;
}
公共长期服务中心(){
返回核心;
}
公共字符串getQ1WinnerAddress(){
返回WinnerAddress;
}
公共长getQ2AwayScore(){
返回q2AwayScore;
}
公共长代码核心(){
返回核心;
}
公共字符串getQ2WinnerAddress(){
返回WinnerAddress;
}
公共长getQ3AwayScore(){
返回q3AwayScore;
}
公共Long-getQ3HomeScore(){
返回核心;
}
公共字符串getQ3WinnerAddress(){
返回WinnerAddress;
}
公共长期getQ4AwayScore(){
返回q4AwayScore;
}
公共长核心(){
返回核心;
}
公共字符串getQ4WinnerAddress(){
返回WinnerAddress;
}
公共字符串getStartTime(){
返回起始时间;
}
公共布尔getWinnersPaid(){
退还已支付的奖金;
}
}
}
<
public class Board {
    private HostData hostData;
    private MetaData metadata; // change to this

    ... constructor, getter, setter
}
public class Board {
    public HostData hostData;
    @PropertyName("metadata")
    public MetaData metaData; // make sure the field is in public

    ... constructor, getter, setter
}