我有3个(POJO)课程,我已经通过Retrofit从NewsApi请求了。我应该使用这个类并创建一个RealmObject。我该怎么做? 这个课程在这里:
public class Source {
@SerializedName("id") @Expose private Object id;
@SerializedName("name") @Expose private String name;
public Object getId() { return id;}
public void setId(Object id) { this.id = id;}
public String getName() { return name;}
public void setName(String name) { this.name = name;}
}
第二课:
public class Article {
@SerializedName("source") @Expose private Source source;
@SerializedName("author") @Expose private String author;
@SerializedName("title") @Expose private String title;
@SerializedName("description") @Expose private String description;
@SerializedName("url") @Expose private String url;
@SerializedName("urlToImage") @Expose private String urlToImage;
@SerializedName("publishedAt") @Expose private String publishedAt;
public Source getSource() {return source;}
public void setSource(Source source) { this.source = source;}
public String getAuthor() { return author;}
public void setAuthor(String author) { this.author = author;}
public String getTitle() {return title;}
public void setTitle(String title) {this.title = title;}
public String getDescription() {return description;}
public void setDescription(String description) {
this.description = description;}
public String getUrl() { return url;}
public void setUrl(String url){this.url = url;}
public String getUrlToImage() {return urlToImage;}
public void setUrlToImage(String urlToImage) {
this.urlToImage = urlToImage;
}
public String getPublishedAt() {
return publishedAt;}
public void setPublishedAt(String publishedAt) {
this.publishedAt = publishedAt;
}
}
第三课
public class ArticlesResponse {
@SerializedName("status") private String status;
@SerializedName("sortBy") private String sortBy;
@SerializedName("source") private String source;
@SerializedName("articles") private List<Article> articles;
public ArticlesResponse() {}
public String getStatus() {return status;}
public void setStatus(String status) { this.status = status;}
public String getSortBy() { return sortBy;}
public void setSortBy(String sortBy) {this.sortBy = sortBy;}
public String getSource() { return source;}
public void setSource(String source) { this.source = source;}
public List<Article> getArticles() { return articles;}
public void setArticles(List<Article> articles) {this.articles = articles;}
public ArticlesResponse getArticleResponse() { return null;}
}
我认为我应该制作三个可以扩展RealmObject的类。
class Source : extends RealmObject {}
class Article : extends RealmObject {and here RealmList<Source> }
class ArticleResponse : extends RealmObject {and here RealmList<Article>}
但是作为对象的字段呢?
private Object id;