嵌套的ForeignCollections总是用RoboSpice和OrmLite插件清空

时间:2014-07-25 17:00:37

标签: ormlite robospice

我很确定这是一个比RoboSpice更多的OrmLite问题,但由于本机文件缓存完美地存储数据,我将针对RoboSpice的OrmLite插件发布此内容。我的问题是嵌套的外部集合总是空的。我的意思是,当解析JSON(没有错误)时,表格不会被填充。

下面是我的json和模特。第一个容器"食谱"作为国外食谱的完美作品。 "相片"也没关系。问题是"网址"我有它们的设置以及ForeignCollection,但db表总是空的。

我可以从我的dbhelper访问数据并手动生成.update()查询来填充表,但这似乎首先打败了插件的目的,所以我假设我做错了。有什么想法吗?

这是我试图用RoboSpice / OrmLite缓存的JSON。

    {
  "recipes": [
    {
      "recipeID": 25508,
      "type": "recipes",
      "title": "titel 1",
      "photo": {
        "photoID": 753228,
        "urls": [
          {
            "url": "http://images.x.com/userphotos/50x50/753228.jpg",
            "height": 50,
            "width": 50
          },
          {
            "url": "http://images.x.com/userphotos/110x110/753228.jpg",
            "height": 110,
            "width": 110
          },
          {
            "url": "http://images.x.com/userphotos/140x140/00/75/32/753228.jpg",
            "height": 140,
            "width": 140
          },
          {
            "url": "http://images.x.com/userphotos/250x250/00/75/32/753228.jpg",
            "height": 250,
            "width": 250
          }
        ]
      },
      "ratingAverage": 4.26,
      "ratingCount": 122,
      "reviewCount": 97,
      "submitter": {
        "userID": 0,
        "name": "name 1",
        "isPro": false,
        "photo": {
          "urls": [
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-50x50.png",
              "height": 50,
              "width": 50
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-110x110.png",
              "height": 110,
              "width": 110
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-140x140.png",
              "height": 140,
              "width": 140
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-250x250.png",
              "height": 250,
              "width": 250
            }
          ]
        }
      },
      "videoID": 3205,
      "links": {
        "parent": {
          "href": "https://apps.beta.x.com/v1/recipes/25508"
        }
      }
    },
    {
      "recipeID": 214802,
      "type": "recipes",
      "title": "title 2",
      "photo": {
        "photoID": 662782,
        "urls": [
          {
            "url": "http://images.x.com/userphotos/50x50/662782.jpg",
            "height": 50,
            "width": 50
          },
          {
            "url": "http://images.x.com/userphotos/110x110/662782.jpg",
            "height": 110,
            "width": 110
          },
          {
            "url": "http://images.x.com/userphotos/140x140/00/66/27/662782.jpg",
            "height": 140,
            "width": 140
          },
          {
            "url": "http://images.x.com/userphotos/250x250/00/66/27/662782.jpg",
            "height": 250,
            "width": 250
          }
        ]
      },
      "ratingAverage": 4.61,
      "ratingCount": 18,
      "reviewCount": 13,
      "submitter": {
        "userID": 0,
        "name": "name 2",
        "isPro": false,
        "photo": {
          "urls": [
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-50x50.png",
              "height": 50,
              "width": 50
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-110x110.png",
              "height": 110,
              "width": 110
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-140x140.png",
              "height": 140,
              "width": 140
            },
            {
              "url": "http://images.x.com/global/profile/nophoto/noprofile-250x250.png",
              "height": 250,
              "width": 250
            }
          ]
        }
      },
      "videoID": 0,
      "links": {
        "parent": {
          "href": "https://apps.beta.x.com/v1/recipes/214802"
        }
      }
    }
  ]
}

以下是相关模型:

@JsonIgnoreProperties(ignoreUnknown = true)
@DatabaseTable
public class Photo {
// id is generated by the database and set on the object automagically
@JsonIgnore
@DatabaseField(columnName = "id", generatedId = true)
int id;

@JsonIgnore
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private Recipe recipe;

@JsonProperty("urls")
@ForeignCollectionField(eager = false)
Collection<PhotoUrl> urls;

public Photo() {
    // needed by Jackson/OrmLite, DO NOT REMOVE!
}

// Getters setters omitted...

@JsonIgnoreProperties(ignoreUnknown = true)
public class PhotoUrl {

// id is generated by the database and set on the object automagically
@JsonIgnore
@DatabaseField(columnName = "id", generatedId = true)
int id;

@JsonIgnore
@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
private Photo photo;

@JsonProperty("url")
@DatabaseField(columnName = "url")
private String url;

@JsonProperty("height")
@DatabaseField(columnName = "height")
private float height;

@JsonProperty("width")
@DatabaseField(columnName = "width")
private float width;

public PhotoUrl() {
    // needed by Jackson/OrmLite, DO NOT REMOVE!
}

// Getters setters omitted...

0 个答案:

没有答案