Search in sources :

Example 1 with JsonValueModule

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);
}
Also used : JsonValueModule(com.couchbase.client.java.json.JsonValueModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JsonValueModule

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;
}
Also used : CryptoManager(com.couchbase.client.core.encryption.CryptoManager) EncryptionModule(com.couchbase.client.java.encryption.databind.jackson.EncryptionModule) JsonValueModule(com.couchbase.client.java.json.JsonValueModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JsonValueModule

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);
    });
}
Also used : JacksonJsonSerializer(com.couchbase.client.java.codec.JacksonJsonSerializer) ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) JacksonJsonSerializer(com.couchbase.client.java.codec.JacksonJsonSerializer) JsonValueModule(com.couchbase.client.java.json.JsonValueModule) JacksonAutoConfiguration(org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with JsonValueModule

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);
}
Also used : EncryptionModule(com.couchbase.client.java.encryption.databind.jackson.EncryptionModule) JsonValueModule(com.couchbase.client.java.json.JsonValueModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonValueModule (com.couchbase.client.java.json.JsonValueModule)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 EncryptionModule (com.couchbase.client.java.encryption.databind.jackson.EncryptionModule)2 CryptoManager (com.couchbase.client.core.encryption.CryptoManager)1 JacksonJsonSerializer (com.couchbase.client.java.codec.JacksonJsonSerializer)1 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)1 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1 JacksonAutoConfiguration (org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration)1