Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Couchbase Java Client in a Dropwizard Project?

I've been looking at the couchbase-java-client project and wondering whether it's possible to use it inside of a dropwizard project.

It seems like it'd be a natural fit, because couchbase is basically a JSON database, but the java client doesn't seem to be compatible with Jackson. As far as I can tell, the couchbase client library includes its own internal implementation of a JSON library that's incompatible with all the other java JSON libs out there, which is really weird.

I found a JacksonTransformers class that looked promising at first. But upon closer inspection, the library is using a shaded version of Jackson (with a rewritten package of com.couchbase.client.deps.com.fasterxml.jackson.core).

Anyhow, since dropwizard uses Jackson and Jersey for marshalling JSON documents through the REST API, what's the least-friction way of using the couchbase-java-client library? Is it even possible in this case?

like image 972
benjismith Avatar asked Nov 04 '14 16:11

benjismith


People also ask

What is Couchbase Java SDK?

The Couchbase Java client allows applications to access a Couchbase database. It offers synchronous APIs as well as reactive and asynchronous equivalents to maximize flexibility and performance.

What is CAS in couchbase?

Write operations on Couchbase accept a parameter cas (create and set). Also the return result object of any non-data fetching query has cas property in it.


1 Answers

It is definitely possible to use Couchbase with Dropwizard. The client SDK provides JSON manipulation objects for the developer's convenience but it also allows for delegating JSON processing to a library like Jackson or GSON. Take a look at the RawJsonDocument class here. Basically, you can use a Stringified JSON (coming out of any framework) to create one of those objects and the client SDK will understand it as a JSON document for any operation i.e.:

String content = "{\"hello\": \"couchbase\", \"active\": true}";
bucket.upsert(RawJsonDocument.create("rawJsonDoc", content));
like image 89
Camilo Crespo Avatar answered Sep 20 '22 01:09

Camilo Crespo