Allow custom EntityConverter



Would it be ok to give a possibility to developers to pass custom EntityConverter into AsyncRepository?
For now it’s hardcoded as DefaultEntityConverter and no possibility to override it

Thanks in advance!



Hi Yuri,

SDC doesn’t allow custom entity converters, the template always uses couchbase converter. If you are interested in async, we have experimental reactive support using rxjava planned for 3.0.0-M2, currently there is only the snapshot.


Hi @subhashni, firstly thanks for all your improvements in the couchbase-sdk.

I would like to request to take one step back. The Couchbase ODM support, though experimental, is a really nice and general concept, where you allow customers to define their own models and just map it to couchbase documents. The EntityConverter is a really nice abstraction for the ODM model mapping:

D fromEntity(EntityDocument<Object> source);

<T> EntityDocument<T> toEntity(D source, Class<T> clazz);

And the CouchbaseAsyncrepository also has a very simple constructor:

public CouchbaseAsyncRepository(AsyncBucket bucket) {
    this.bucket = bucket;
    this.converter = new DefaultEntityConverter();

All we are asking for is only to allow the converter as an optional constructor argument :slight_smile:

public CouchbaseAsyncRepository(AsyncBucket bucket) {
    this(bucket, new DefaultEntityConverter());

public CouchbaseAsyncRepository(AsyncBucket bucket, EntityConverter converter) {
    this.bucket = bucket;
    this.converter = converter;

That’s all :slight_smile: That makes so many things easier for the “ODM” as a concept. Take our case for example, we are enterprise users of Couchbase and we run 30 enterprise nodes (going up all the year) in

We use Google protocol buffers as the schema definition for many things in our company: static data, couchbase data, over-the-wire contracts/data, etc.

# simple proto definition of a model
message MyCouchbaseDoc {
  string id ..
  int32 version...

We know other companies that use JSON schema, XML schema and much more for model definition.

We know how to convert our model to a couchbase RawJsonDocument very well. Our EntityConverter is domain specific, faster (uses zero reflections), and what’s more, its trivial enough that we can open source and write a blog on it: Couchbase with protocol buffer schemas.

The EntityConverter already looks like a nicely designed interface. Its only the CouchbaseAsyncRepository constructor that is holding it back. IMHO, Just allowing the constructor to accept an EntityConverter would make the ODM much more flexible for customers, and its quite a trivial change too :slight_smile:

I have followed, signed the CLA and raised a PR here:

Would be great if you can have a look :slight_smile: