Closed moloch-- closed 3 years ago
ReQL API documentation describes what data types are returned in the ReQL language.
https://rethinkdb.com/docs/data-types/
Every client driver has its own way of reading in/out ReQL queries, and Java's run
command, I presume, has a return type of Result<Object>
no matter what the ReQL expression is.
Result
is one of your ways to handle data. It exposes all the bells and whistles for you to handle stuff such as sequences of objects.
Since the driver can't predict the return type of a given function, you gotta pass to it a optional class or a type reference for it to cast your objects.
You can use r.dbList().run(dbConn, Types.listOf(String.class))
to get a Result with a single List<String>
inside. Or use runAtom(dbConn, Types.listOf(String.class))
utility class, which would be somewhat equivalent to the previous syntax.
Thanks guys I was able to figure it out by reading the Java driver source code, with some trial and error. However, it would be nice to have some of this information in the official documentation!
Is your feature request related to a problem? Please describe.
The documentation on https://rethinkdb.com/api/java/ seems to be out of date with v2.4.1? None of the return types seem to be correct.
For example, https://rethinkdb.com/api/java/db_list says
.dbList()
returns an array but in practice seems to return aResult<Object>
? TheResult
class also seems undocumented:The documentation also says that
.toJson
should return aString
https://rethinkdb.com/api/java/to_json_string/#wrapper --In practice this method also returns a seems to return aResult<Object>
?There doesn't seem to be any examples or documentation on how to handle a
Result<Object>
or covert it to the types the documentation says should be returned. I can tell the class does contain the data I'm looking for using%s
but there doesn't seem to be any documented way to access that data.