Hi Rob,
If your return type is not a document you have 4 options:
1. use String as return type, which give you a raw json
ArangoCursor<String> cursor = arangoDB.db().query("your query", null, null,
String.class);
2. use VPackSlice as return type, get the documents from it and deserialize
them with the class VPack to BaseDocument
VPack deserialiser = new VPack.Builder().build();
ArangoCursor<VPackSlice> cursor = arangoDB.db().query("your query", null,
null, VPackSlice.class);
for (; cursor.hasNext();) {
VPackSlice vpack = cursor.next();
BaseDocument doc1 = deserialiser.deserialize(vpack.get("document1"),
BaseDocument.class);
BaseDocument doc2 = deserialiser.deserialize(vpack.get("document2"),
BaseDocument.class);
}
3. use Map as return type
ArangoCursor<Map> cursor = arangoDB.db().query("your query", null, null, Map
.class);
for (; cursor.hasNext();) {
Map<String, Object> result = cursor.next();
Map<String, Object> document1 = (Map<String, Object>) result.get(
"document1");
Map<String, Object> document2 = (Map<String, Object>) result.get(
"document2");
}
4. make your own POJO which reflect your qery result and use it as return
type
public class MyResult {
private BaseDocument document1;
private BaseDocument document2;
public MyResult() {
super();
}
// setter + getter
}
ArangoCursor<MyResult> cursor = arangoDB.db().query("your query", null, null
, MyResult.class);
for (; cursor.hasNext();) {
MyResult result = cursor.next();
BaseDocument document1 = result.getDocument1();
BaseDocument document2 = result.getDocument2();
}
If you have nested objects and want to use BaseDocument, you can access
them with getAttribute(key) and cast the Object result to Map<String,
Object> like in option 3.
BaseDocument baseDocument = ...
Map<String, Object> nestedObj = (Map<String, Object>) baseDocument.
getAttribute("nestedObjKey");
Generally you do not have to use BaseDocument. It is just a little helper
for small things, where you do not have a POJO for. The
driver automatically de-/serialize your POJOs when
insert/get/update/replace or query.
The de-/serialization is highly configurable. see documentation:
https://github.com/arangodb/arangodb-java-driver/blob/master/docs/serialization.md
For additional examples of working with the different types for documents,
take a look here:
https://github.com/arangodb/arangodb-java-driver/tree/master/src/test/java/com/arangodb/example/document
Mark
Am Donnerstag, 27. Oktober 2016 09:42:52 UTC+2 schrieb Rob Keevil:
>
> Hi,
>
> I'm testing the new java driver, which gives a nice speed up over the v3
> driver. I have two questions however that I can't figure out from the docs.
>
> Firstly, what object type do I use if the return from arangoDB isn't a
> document? One query I'm using returns pairs of documents, so therefore
> doesn't have _key, id etc at the root. This causes a VPackParserException.
> Previously I returned this as a raw Json result, but that doesn't seem to
> be available anymore.
>
> Secondly, how do I access nested objects in a BaseDocument? I can see
> that in the VPackSlice format I can just do
> doc.get("document1").get("_key").getAsString, but I can't find an
> equivalent for BaseDocuments. Annoyingly if I use VPackSlice instead it
> seems to send Apache Flink's memory manager crazy.
>
> Thanks,
> Rob
>
--
You received this message because you are subscribed to the Google Groups
"ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.