So you are retrieving keys without knowing the type in advance (or even expecting any particular type)?
There isn’t really a way of retrieving the value type in advance. First, all the JsonXXXDocument are stored in couchbase using a common JSON flag, so you cannot distinguish between them using metadata only… StringDocument uses another flag which is incompatible.
Maybe for the JsonDocument and JsonBooleanDocument you can replace it with RawJsonDocument? It will then be up to you to decode the raw JSON representation to your expected value type (probably Object?). But you’d still have to manage the case where transcoding to RawJsonDocument cannot happen (in which case this would be a StringDocument).
If in your data modelling you prefix your keys with the logical type, this could help you decided which target class to use during retrieval. For instance you want to store cars as JsonDocument and comments as StringDocument, then have your keys prefixed with “car::” or “comment::”.
if (key.startsWith("car::") {
JsonDocument carDoc = bucket.get(key, JsonDocument.class);
//do something with car document
} else if (key.startsWith("comment::") {
StringDocument commentDoc = bucket.get(key, StringDocument.class);
//do something with comment document
}
Ok understood… It would have been great to have such kind of method in the Bucket class to retrieve the value type though. But I might imagine it’s not that simple to implement.