Following another question I have started splitting some of my “entities” into two documents that I can join together on a pre-build key. This is really great.
However, sometimes I do have the direct id to look up the “main” document - and subsequently the “sub” document. But then I have two JsonDocuments instead of just one “node” with the data - and that is then different when I want to populate it via a Java object inside my application.
So is there a way to “join” (or more correctly “nest”) the contents of two JsonDocument contents - just temporary for building my POJO ob ject?
Oh, and this is what I do right now - but it seems kind of “clumpsy”…
JsonDocument doc = getDb().get(getDocId(key));
if (null != doc) {
JsonDocument privDoc = getDb().get(getPrivateDocId(key));
if (null != privDoc) {
Map<String, Object> fields = doc.content().toMap();
fields.putAll(privDoc.content().toMap());
Util.trace("Combined: " + JsonObject.from(fields));
user = loadFromDocument(JsonObject.from(fields));
} else {
user = loadFromDocument(doc.content());
}
}