Search code examples
spring-datacouchbasespring-data-couchbase

_class field and spring data couchbase


So, I was trying to find a way to remove/rename( and change the fields value ) the _class field from the document generated by spring data couchbase as the document is going to be stored by one service and in all likeliness be consumed by someone totally different.

I was playing around with the api for spring couchbase and through a bit of trial and error found that I can rename the _class field with a custom value using the following way ->

1) Override the typeKey method in a class inheriting AbstractCouchbaseConfiguration . For example, let's say we overrided typeKey to do the following ->

@Override public String typeKey() { return "type"; }

2) In the POJO that stores the data into couchbase, add a field with the same field name as what you gave into the return value of the typeKey method and give it the custom value as needed -

private final String type = "studentDoc";

I wanted to check if this is a valid way of going about this or/and some better way is available to do something like this now


Solution

  • That is the only way to do it with spring data at this moment, we would like to add a few extra ways to do that but we are limited to the Spring Data interface contracts. That is why most of the extra configs are done via AbstractCouchbaseConfiguration.