如何忽略房间实体不需要的键

时间:2018-07-07 12:23:20

标签: android json android-room

我正在尝试创建一个房间实体类。但是有一些我不需要的json对象。所以我很困惑如何忽略那些对象。

下面是JSON:

     {  
       "batchcomplete":true,
       "continue":{  
          "gpsoffset":10,
          "continue":"gpsoffset||"
       },
       "query":{  
          "redirects":[  
             {  
                "index":4,
                "from":"Sachin Tyagi",
                "to":"Solhah Singaarr"
             },
             {  
                "index":3,
                "from":"Sachin The Film",
                "to":"Sachin: A Billion Dreams"
             }
          ],
          "pages":[  
             {  
                "pageid":57570,
                "ns":0,
                "title":"Sachin Tendulkar",
                "index":1,
                "thumbnail":{  
                   "source":"https://upload.wikimedia.org/wikipedia/commons/thumb/2/25/Sachin_Tendulkar_at_MRF_Promotion_Event.jpg/50px-Sachin_Tendulkar_at_MRF_Promotion_Event.jpg",
                   "width":50,
                   "height":45
                },
                "terms":{  
                   "description":[  
                      "Indian cricketer"
                   ]
                }
}

我也尝试使用@Ignore,但这对我不起作用。

这是我的Entity类:

@Entity(tableName = "ResponseEntity")
public class PageDetailEntity {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id")
    private int id;

    @Ignore
    @ColumnInfo(name = "batchcomplete")
    private boolean batchcomplete;
    @Ignore
    @TypeConverters(ContinueModelConverter.class)
    public List<ContinueModel> mContinue;

    @TypeConverters(QueryModelConverter.class)
    private List<QueryModel>queryModel;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public boolean isBatchcomplete() {
        return batchcomplete;
    }

    public void setBatchcomplete(boolean batchcomplete) {
        this.batchcomplete = batchcomplete;
    }

    public List<ContinueModel> getmContinue() {
        return mContinue;
    }

    public void setmContinue(List<ContinueModel> mContinue) {
        this.mContinue = mContinue;
    }

    public List<QueryModel> getQueryModel() {
        return queryModel;
    }

    public void setQueryModel(List<QueryModel> queryModel) {
        this.queryModel = queryModel;
    }
}

我只需要页面数组。有人可以指导我如何创建仅具有用于房间的页面数组的实体类。

1 个答案:

答案 0 :(得分:0)

您可以使用来自{p>的numeric批注

@Ignore

Room不会保留用import android.arch.persistence.room.Ignore 注释的字段。

@Ignore