Search in sources :

Example 11 with JsonSerializer

use of com.couchbase.client.java.codec.JsonSerializer in project spring-boot by spring-projects.

the class CouchbaseAutoConfigurationTests method customizeJsonSerializer.

@Test
void customizeJsonSerializer() {
    JsonSerializer customJsonSerializer = mock(JsonSerializer.class);
    this.contextRunner.withUserConfiguration(CouchbaseTestConfiguration.class).withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class)).withBean(ClusterEnvironmentBuilderCustomizer.class, () -> (builder) -> builder.jsonSerializer(customJsonSerializer)).withPropertyValues("spring.couchbase.connection-string=localhost").run((context) -> {
        ClusterEnvironment env = context.getBean(ClusterEnvironment.class);
        JsonSerializer serializer = env.jsonSerializer();
        assertThat(serializer).extracting("wrapped").isSameAs(customJsonSerializer);
    });
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) JacksonJsonSerializer(com.couchbase.client.java.codec.JacksonJsonSerializer) Test(org.junit.jupiter.api.Test)

Example 12 with JsonSerializer

use of com.couchbase.client.java.codec.JsonSerializer 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 13 with JsonSerializer

use of com.couchbase.client.java.codec.JsonSerializer in project couchbase-jvm-clients by couchbase.

the class AsyncScope method analyticsQuery.

/**
 * Performs an Analytics query with custom {@link AnalyticsOptions}.
 *
 * @param statement the Analytics query statement as a raw string.
 * @param options the custom options for this analytics query.
 * @return the {@link AnalyticsResult} once the response arrives successfully.
 */
public CompletableFuture<AnalyticsResult> analyticsQuery(final String statement, final AnalyticsOptions options) {
    notNull(options, "AnalyticsOptions", () -> new ReducedAnalyticsErrorContext(statement));
    AnalyticsOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment.jsonSerializer() : opts.serializer();
    return AnalyticsAccessor.analyticsQueryAsync(core, analyticsRequest(statement, opts), serializer);
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) AnalyticsOptions(com.couchbase.client.java.analytics.AnalyticsOptions)

Example 14 with JsonSerializer

use of com.couchbase.client.java.codec.JsonSerializer in project couchbase-jvm-clients by couchbase.

the class ReactiveCluster method searchQuery.

/**
 * Performs a Full Text Search (FTS) query with custom {@link SearchOptions}.
 *
 * @param query the query, in the form of a {@link SearchQuery}
 * @param options the custom options for this query.
 * @return the {@link SearchRequest} once the response arrives successfully, inside a {@link Mono}
 */
public Mono<ReactiveSearchResult> searchQuery(final String indexName, final SearchQuery query, final SearchOptions options) {
    notNull(query, "SearchQuery", () -> new ReducedSearchErrorContext(indexName, null));
    notNull(options, "SearchOptions", () -> new ReducedSearchErrorContext(indexName, query.export().toMap()));
    SearchOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment().jsonSerializer() : opts.serializer();
    return Mono.defer(() -> {
        return SearchAccessor.searchQueryReactive(asyncCluster.core(), asyncCluster.searchRequest(indexName, query, opts), serializer);
    });
}
Also used : ReducedSearchErrorContext(com.couchbase.client.core.error.context.ReducedSearchErrorContext) SearchOptions(com.couchbase.client.java.search.SearchOptions) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer)

Example 15 with JsonSerializer

use of com.couchbase.client.java.codec.JsonSerializer in project couchbase-jvm-clients by couchbase.

the class AsyncBucket method viewQuery.

public CompletableFuture<ViewResult> viewQuery(final String designDoc, final String viewName, final ViewOptions options) {
    notNull(options, "ViewOptions", () -> new ReducedViewErrorContext(designDoc, viewName, name));
    ViewOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment.jsonSerializer() : opts.serializer();
    return ViewAccessor.viewQueryAsync(core, viewRequest(designDoc, viewName, opts), serializer);
}
Also used : ViewOptions(com.couchbase.client.java.view.ViewOptions) ReducedViewErrorContext(com.couchbase.client.core.error.context.ReducedViewErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer)

Aggregations

JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)18 ReducedAnalyticsErrorContext (com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext)4 ReducedQueryErrorContext (com.couchbase.client.core.error.context.ReducedQueryErrorContext)4 AnalyticsOptions (com.couchbase.client.java.analytics.AnalyticsOptions)4 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)4 QueryOptions (com.couchbase.client.java.query.QueryOptions)4 LookupInOptions (com.couchbase.client.java.kv.LookupInOptions)3 ReducedSearchErrorContext (com.couchbase.client.core.error.context.ReducedSearchErrorContext)2 ReducedViewErrorContext (com.couchbase.client.core.error.context.ReducedViewErrorContext)2 SubdocGetRequest (com.couchbase.client.core.msg.kv.SubdocGetRequest)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 JacksonJsonSerializer (com.couchbase.client.java.codec.JacksonJsonSerializer)2 SearchOptions (com.couchbase.client.java.search.SearchOptions)2 Duration (java.time.Duration)2 Test (org.junit.jupiter.api.Test)2 Core (com.couchbase.client.core.Core)1 CoreContext (com.couchbase.client.core.CoreContext)1 Stability (com.couchbase.client.core.annotation.Stability)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1