Search in sources :

Example 1 with JsonNode

use of com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode in project kafka-connect-couchbase by couchbase.

the class DocumentIdExtractorTest method assertJsonEquals.

private static void assertJsonEquals(String expected, String actual) throws IOException {
    JsonNode parsedExpected = objectMapper.readTree(expected);
    JsonNode parsedActual = objectMapper.readTree(actual);
    assertEquals(parsedExpected, parsedActual);
}
Also used : JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)

Example 2 with JsonNode

use of com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode in project couchbase-jvm-clients by couchbase.

the class CoreBucketManager method getAllBuckets.

public CompletableFuture<Map<String, byte[]>> getAllBuckets(CoreCommonOptions options) {
    return httpClient.get(pathForBuckets(), options).trace(TracingIdentifiers.SPAN_REQUEST_MB_GET_ALL_BUCKETS).exec(core).thenApply(response -> {
        JsonNode tree = Mapper.decodeIntoTree(response.content());
        Map<String, byte[]> out = new HashMap<>();
        for (final JsonNode bucket : tree) {
            String bucketName = requireNonNull(bucket.get("name").textValue(), "Bucket json is missing 'name' field: " + redactMeta(bucket));
            out.put(bucketName, Mapper.encodeAsBytes(bucket));
        }
        return out;
    });
}
Also used : HashMap(java.util.HashMap) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)

Example 3 with JsonNode

use of com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode in project couchbase-jvm-clients by couchbase.

the class AsyncSearchIndexManager method getAllIndexes.

/**
 * Fetches all indexes from the server.
 *
 * @return a {@link CompletableFuture} with all index definitions once complete.
 */
public CompletableFuture<List<SearchIndex>> getAllIndexes(final GetAllSearchIndexesOptions options) {
    return searchHttpClient.get(path(indexesPath()), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MS_GET_ALL_INDEXES).exec(core).thenApply(response -> {
        JsonNode rootNode = Mapper.decodeIntoTree(response.content());
        JsonNode indexDefs = rootNode.get("indexDefs").get("indexDefs");
        Map<String, SearchIndex> indexes = Mapper.convertValue(indexDefs, new TypeReference<Map<String, SearchIndex>>() {
        });
        return new ArrayList<>(indexes.values());
    });
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map)

Example 4 with JsonNode

use of com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode in project couchbase-jvm-clients by couchbase.

the class AsyncEventingFunctionManager method decodeFunctions.

/**
 * Decodes the encoded JSON representation of 0 or more functions into a list of
 * {@link EventingFunction EventingFunctions}.
 *
 * @param encoded the encoded JSON.
 * @return a (potentially empty) list of eventing functions after decoding.
 */
private static List<EventingFunction> decodeFunctions(final byte[] encoded) {
    JsonNode encodedFunctions = Mapper.decodeIntoTree(encoded);
    List<EventingFunction> functions = new ArrayList<>();
    for (JsonNode encodedFunction : encodedFunctions) {
        functions.add(decodeFunction(Mapper.encodeAsBytes(encodedFunction)));
    }
    return functions;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)

Example 5 with JsonNode

use of com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode in project couchbase-jvm-clients by couchbase.

the class EventingFunction method fromExportedFunctions.

/**
 * Creates a list of {@link EventingFunction}s from a raw JSON, usually exported from the server UI.
 *
 * @param encoded the encoded functions to load.
 * @return the created list of {@link EventingFunction}s.
 */
@Stability.Volatile
public static List<EventingFunction> fromExportedFunctions(final byte[] encoded) {
    JsonNode encodedFunctions = Mapper.decodeIntoTree(encoded);
    if (!encodedFunctions.isArray()) {
        throw new InvalidArgumentException("The encoded JSON must be a JSON array of functions", null, null);
    }
    List<EventingFunction> functions = new ArrayList<>();
    for (JsonNode function : encodedFunctions) {
        functions.add(fromFunction(Mapper.encodeAsBytes(function)));
    }
    return functions;
}
Also used : InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) ArrayList(java.util.ArrayList) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)12 ArrayList (java.util.ArrayList)5 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)2 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)2 Map (java.util.Map)2 Core (com.couchbase.client.core.Core)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 TypeReference (com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference)1 ObjectNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode)1 HttpHeaderNames (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 CoreHttpResponse (com.couchbase.client.core.endpoint.http.CoreHttpResponse)1 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)1 FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)1 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)1 Mapper (com.couchbase.client.core.json.Mapper)1 RequestTarget (com.couchbase.client.core.msg.RequestTarget)1