use of com.couchbase.client.java.json.JsonValueModule in project couchbase-jvm-clients by couchbase.
the class JacksonJsonSerializerTest method createSerializer.
private static JsonSerializer createSerializer() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonValueModule());
return JacksonJsonSerializer.create(mapper);
}
use of com.couchbase.client.java.json.JsonValueModule in project spring-data-couchbase by spring-projects.
the class AbstractCouchbaseConfiguration method couchbaseObjectMapper.
/**
* Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
*
* @return ObjectMapper
*/
public ObjectMapper couchbaseObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JsonValueModule());
CryptoManager cryptoManager = null;
if (cryptoManager != null) {
mapper.registerModule(new EncryptionModule(cryptoManager));
}
return mapper;
}
use of com.couchbase.client.java.json.JsonValueModule in project spring-boot by spring-projects.
the class CouchbaseAutoConfigurationTests method whenObjectMapperBeanIsDefinedThenClusterEnvironmentObjectMapperIsDerivedFromIt.
@Test
void whenObjectMapperBeanIsDefinedThenClusterEnvironmentObjectMapperIsDerivedFromIt() {
this.contextRunner.withUserConfiguration(CouchbaseTestConfiguration.class).withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class)).withPropertyValues("spring.couchbase.connection-string=localhost").run((context) -> {
ClusterEnvironment env = context.getBean(ClusterEnvironment.class);
Set<Object> expectedModuleIds = new HashSet<>(context.getBean(ObjectMapper.class).getRegisteredModuleIds());
expectedModuleIds.add(new JsonValueModule().getTypeId());
JsonSerializer serializer = env.jsonSerializer();
assertThat(serializer).extracting("wrapped").isInstanceOf(JacksonJsonSerializer.class).extracting("mapper", as(InstanceOfAssertFactories.type(ObjectMapper.class))).extracting(ObjectMapper::getRegisteredModuleIds).isEqualTo(expectedModuleIds);
});
}
use of com.couchbase.client.java.json.JsonValueModule in project couchbase-jvm-clients by couchbase.
the class JacksonJsonSerializer method create.
/**
* Returns a new instance backed by a default ObjectMapper
* with optional encryption support.
*
* @param cryptoManager (nullable) The manager to use for activating the
* {@link Encrypted} annotation, or null to disable encryption support.
* @return the Jackson JSON serializer with a provided crypto manager.
*/
public static JacksonJsonSerializer create(CryptoManager cryptoManager) {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonValueModule());
if (cryptoManager != null) {
mapper.registerModule(new EncryptionModule(cryptoManager));
}
return new JacksonJsonSerializer(mapper);
}
Aggregations