Skip to content

Instantly share code, notes, and snippets.

@daschl daschl/custom.java
Created Mar 2, 2018

Embed
What would you like to do?
class Config extends AbstractCouchbaseConfiguration {
protected List<String> getBootstrapHosts() {
return Arrays.asList("127.0.0.1");
}
protected String getBucketName() {
return "travel-sample";
}
protected String getBucketPassword() {
return "";
}
@Override
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
return new MyMappingCouchbaseConverter(couchbaseMappingContext(), typeKey());
}
}
class MyMappingCouchbaseConverter extends MappingCouchbaseConverter {
public MyMappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) {
super(mappingContext);
}
public MyMappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey) {
super(mappingContext, typeKey);
}
@Override
public void write(Object source, CouchbaseDocument target) {
if (source instanceof MyEntity) {
// todo: custom conversion from your entity into target
} else {
super.write(source, target);
}
}
@Override
public <R> R read(Class<R> clazz, CouchbaseDocument source) {
if (MyEntity.class.isAssignableFrom(clazz)) {
// todo: init clazz and assign fields from source
} else {
return super.read(clazz, source);
}
}
}
class MyEntity {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.