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
“data”:{“nodeType”:“OBJECT”,“object”:true,“array”:false,“float”:false,“null”:false,“containerNode”:true,“integralNumber”:false,“floatingPointNumber”:false,“valueNode”:false,“missingNode”:false,“pojo”:false,“number”:false,“int”:false,“long”:false,“double”:false,“bigDecimal”:false,“bigInteger”:false,“textual”:false,“boolean”:false,“binary”:false,“short”:false}
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?
Thanks,
David
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
.
Thanks,
David
2 Likes