Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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
如何使用ActiveAndroid加载整个对象(带列表)_Android_Sql_Sqlite_Activeandroid - Fatal编程技术网

如何使用ActiveAndroid加载整个对象(带列表)

如何使用ActiveAndroid加载整个对象(带列表),android,sql,sqlite,activeandroid,Android,Sql,Sqlite,Activeandroid,我有一个简单的模型: @Table(name = "Books") public class Book extends Model { @Column(name = "title") String title; //Variable to cache the pages List<Page> pages; public Book(){ } public List<Page> getPages() {

我有一个简单的模型:

@Table(name = "Books")
public class Book extends Model {

    @Column(name = "title")
    String title;    

    //Variable to cache the pages
    List<Page> pages;

    public Book(){

    }

    public List<Page> getPages() {
        if (pages==null) pages=getMany(Page.class, "book");
        return pages;
    }
}
我遇到的问题是,我想将整个book对象(及其所有子对象)序列化为JSon(使用GSon),在检索对象时,这些对象没有加载

public String toJSon(long id){
    Book b = new Select().from(Book.class).where("id = ?", id).executeSingle();
    // At this point, the array of pages is obviously empty, and I don't want to hard-call "getPages" because in the future every page will have words, and I would then have to iterate every page, etc..
    Gson gson = new GsonBuilder().create();
    return gson.toJson(b);
}
如何一次加载Book对象及其所有页面

public String toJSon(long id){
    Book b = new Select().from(Book.class).where("id = ?", id).executeSingle();
    // At this point, the array of pages is obviously empty, and I don't want to hard-call "getPages" because in the future every page will have words, and I would then have to iterate every page, etc..
    Gson gson = new GsonBuilder().create();
    return gson.toJson(b);
}