Convert Document Object to String

Hi, I was able to read a user document from couchbase DB. when I convert the user object to string, I can able to see all meta data stuff as shown below. how can i get rid of that when converting object to string? I’m using ObjectMapper to convert object to string. something like this mapper.writeValueAsString(Object);
Please advise


Assuming you’re reading the document with some code like this:

String userId = "123";
JsonDocument userDocument = bucket.get(userId);
JsonObject userObject = userDocument.content();

then you can get the JSON string representation of the user by calling toString() on the JsonObject:

String userJson = userObject.toString();

If I’ve misunderstood your situation, can you share the code that has the problem?


Alternatively, a more efficient way to get the document content as a JSON string is to read the document as a RawJsonDocument like this:

String userId = "123";
RawJsonDocument userDocument = bucket.get(RawJsonDocument.create(userId));
String userJson = userDocument.content(); 

Incidentally, this is the recommended approach if you want to do your own data binding with your own Jackson ObjectMapper.