I have two db collections Agency & Program
where an Agency
can have many programs
and all the further concept implementation is using Programs only. So I have created two 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
}
When I run AQL : for a in AGENCY return merge(a, {PROGRAMS: (for p in PROGRAMS FILTER p.AGENCY == a._id return p)})
I get following 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"
}
]
}
]
When I run this query from arangodb-java-driver 4.1
it throws an exception while deserialization
com.arangodb.velocypack.exception.VPackValueTypeException: Expecting type OBJECT
and if I comment these lines from Agency.java it works fine, But I need to have List in agency.
@Expose(serialize = false, deserialize = true)
@SerializedName("PROGRAMS")
private List<Program> programs;
Is there a way to handle lists in such cases ? Please suggest a way to overcome this.. Thanks :)
in your POJO
Program
you have a field agency which is from typeAgency
but in the JSON you get from the DB this field is from type string. Change typeAgency
toString
and your code works.update:
To get the result from your query which fits into your current java bean, run:
for a in AGENCY return merge(a, {PROGRAMS: (for p in PROGRAMS FILTER p.AGENCY == a._id return merge(p, {AGENCY: a}))})