DATACOUCH-30 - ObjectMapper configuration must be supported
Allow for a custom ObjectMapper to be used.
This commit is contained in:
committed by
Michael Nitschinger
parent
51dea603de
commit
7d79d79e28
@@ -66,14 +66,12 @@ public class TestApplicationConfig extends AbstractCouchbaseConfiguration {
|
||||
return new BucketCreator(couchbaseHost(), couchbaseAdminUser(), couchbaseAdminPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
@Override
|
||||
@DependsOn("bucketCreator")
|
||||
public CouchbaseClient couchbaseClient() throws Exception {
|
||||
return new CouchbaseClient(
|
||||
Arrays.asList(new URI(couchbaseHost())), couchbaseBucket(), couchbasePassword());
|
||||
return new CouchbaseClient(Arrays.asList(new URI(couchbaseHost())), couchbaseBucket(), couchbasePassword());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.couchbase.client.CouchbaseClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.couchbase.TestApplicationConfig;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
@@ -47,14 +48,13 @@ public class AbstractCouchbaseConfigurationTests {
|
||||
@Test
|
||||
public void usesConfigClassPackageAsBaseMappingPackage() throws Exception {
|
||||
AbstractCouchbaseConfiguration config = new SampleCouchbaseConfiguration();
|
||||
|
||||
assertEquals(config.getMappingBasePackage(),
|
||||
SampleCouchbaseConfiguration.class.getPackage().getName());
|
||||
assertEquals(config.getMappingBasePackage(), SampleCouchbaseConfiguration.class.getPackage().getName());
|
||||
assertEquals(config.getInitialEntitySet().size(), 1);
|
||||
assertTrue(config.getInitialEntitySet().contains(Entity.class));
|
||||
}
|
||||
|
||||
class SampleCouchbaseConfiguration extends AbstractCouchbaseConfiguration {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public CouchbaseClient couchbaseClient() throws Exception {
|
||||
@@ -64,5 +64,6 @@ public class AbstractCouchbaseConfigurationTests {
|
||||
|
||||
@Document
|
||||
static class Entity {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,14 @@ public class CouchbaseTemplateParserIntegrationTests {
|
||||
factory.getBean("couchbaseTemplate");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsCouchbaseTemplateWithTranslationServiceAttributesCorrectly() {
|
||||
reader.loadBeanDefinitions(new ClassPathResource("namespace/couchbase-template-with-translation-service-bean.xml"));
|
||||
|
||||
BeanDefinition definition = factory.getBeanDefinition("couchbaseTemplate");
|
||||
assertEquals(2, definition.getConstructorArgumentValues().getArgumentCount());
|
||||
|
||||
factory.getBean("couchbaseTemplate");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
<couchbase:couchbase/>
|
||||
|
||||
<couchbase:couchbase id="couchbase2" host="localhost" bucket="default" password="" />
|
||||
<couchbase:couchbase id="couchbase2" host="localhost" bucket="default" password=""/>
|
||||
|
||||
<couchbase:translation-service objectMapper="myCustomObjectMapper"/>
|
||||
|
||||
<bean id="myCustomObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:couchbase="http://www.springframework.org/schema/data/couchbase"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<couchbase:couchbase/>
|
||||
|
||||
<couchbase:template translation-service-ref="myCustomTranslationService"/>
|
||||
|
||||
<bean id="myCustomTranslationService" class="org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user