我有两个数据库集合Agency & Program,其中Agency可以具有许多programs,所有进一步的概念实现都仅使用程序。所以我创建了两个POJO

public class Agency implements Serializable {
    @DocumentField(DocumentField.Type.ID)
    private String agencyId;

    @DocumentField(DocumentField.Type.KEY)
    @SerializedName("AGENCYNAME")
    private String agencyName;

    @SerializedName("SHORTNAME")
    private String shortName;

    @Expose(serialize = false, deserialize = true)
    @SerializedName("PROGRAMS")
    private List<Program> programs;

    // Other fields with Getter & Setters
}


public class Program implements Serializable {

    @DocumentField(DocumentField.Type.ID)
    private String programId;

    @SerializedName("PROGRAMNAME")
    private String programName;

    @DocumentField(DocumentField.Type.KEY)
    @SerializedName("SHORTNAME")
    private String shortName;

    @SerializedName("AGENCY")
    private Agency agency;

    // Other fields with Getter & Setters
}


当我运行AQL : for a in AGENCY return merge(a, {PROGRAMS: (for p in PROGRAMS FILTER p.AGENCY == a._id return p)})

我得到了JSON

[
  {
    "AGENCYNAME": "Dummy Agency 1",
    "SHORTNAME": "DA1",
    "_id": "AGENCY/1062620",
    "_key": "1062620",
    "_rev": "_URnzj-C---",
    "PROGRAMS": [
      {
        "_key": "DA1DP1",
        "_id": "PROGRAMS/DA1DP1",
        "_rev": "_UQ6dGOG---",
        "AGENCY": "AGENCY/1062620",
        "PROGRAMNAME": "DA1 Dummy Program 1",
        "SHORTNAME": "DA1DP1"
      }
    ]
  },
  {
    "AGENCYNAME": "Dummy Agency 2",
    "SHORTNAME": "DA2",
    "_id": "AGENCY/1062358",
    "_key": "1062358",
    "_rev": "_URnzj-C---",
    "PROGRAMS": [
      {
        "_key": "DA2DP1",
        "_id": "PROGRAMS/DA2DP1",
        "_rev": "_UQ6dGOG---",
        "AGENCY": "AGENCY/1062358",
        "PROGRAMNAME": "DA2 Dummy Program 1",
        "SHORTNAME": "DA2DP1"
      }
    ]
  }
]


当我从arangodb-java-driver 4.1运行此查询时,在反序列化时会引发异常
com.arangodb.velocypack.exception.VPackValueTypeException: Expecting type OBJECT

如果我从Agency.java注释这些行,就可以正常工作,但是我需要在代理商中有List。

    @Expose(serialize = false, deserialize = true)
    @SerializedName("PROGRAMS")
    private List<Program> programs;


在这种情况下是否可以处理列表?
请提出解决方法。
谢谢 :)

最佳答案

在POJO Program中,您有一个来自字段Agency的字段代理,但在从DB中获取的JSON中,此字段是从字符串类型中获得的。将类型Agency更改为String,您的代码即可工作。

更新:

要从适合当前Java bean的查询中获取结果,请运行:

for a in AGENCY return merge(a, {PROGRAMS: (for p in PROGRAMS FILTER p.AGENCY == a._id return merge(p, {AGENCY: a}))})

关于java - 在ArrayList中链接两个ArangoDB集合时反序列化问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41331709/

10-10 05:47