如何忽略文件室实体不需要的键



我正在尝试创建一个房间实体类。但是有一些我不需要的 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(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;
}
}

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

您可以使用来自@Ignore注释

import android.arch.persistence.room.Ignore

Room 不会保留用@Ignore注释的字段。

@Ignore
public String name;

最新更新