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);
}
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;
});
}
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());
});
}
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;
}
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;
}
Aggregations