3

I use CouchbaseRepository in my project but sometimes I use lower level couchbase sdk methods to retrieve JsonDocument. Is there a way I can use spring-data-couchbase to convert a JsonDocument to lets say a User?

This is all done internally in CouchbaseTemplate in the method private <T> T mapToEntity(String id, Document<String> data, Class<T> entityClass)

But as you can see it's private so I can't call it myself.

prettyvoid
  • 3,446
  • 6
  • 36
  • 60

1 Answers1

1

You can create a wrapper which uses Jackson to convert the JsonDocument to any object you want.

mapper.readValue(doc.content().toString(), SomeClass.class);

The first argument is the JsonDocument, the content method is what contains the actual Json.

  • Upvoted you but I was looking for a way to use the same code that `spring-data-couchbase` uses because a new ObjectMapper will not have the configuration that was defined in my couchbase configuration `CouchbaseConfig extends AbstractCouchbaseConfiguration` – prettyvoid Dec 11 '17 at 12:12