Java Code Examples for io.vertx.core.buffer.Buffer#toJsonArray()

The following examples show how to use io.vertx.core.buffer.Buffer#toJsonArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileBasedCredentialsService.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
private Future<Void> addAll(final Buffer credentials) {
    final Promise<Void> result = Promise.promise();
    try {
        int credentialsCount = 0;
        final JsonArray allObjects = credentials.toJsonArray();
        LOG.debug("trying to load credentials for {} tenants", allObjects.size());
        for (final Object obj : allObjects) {
            if (JsonObject.class.isInstance(obj)) {
                credentialsCount += addCredentialsForTenant((JsonObject) obj);
            }
        }
        LOG.info("successfully loaded {} credentials from file [{}]", credentialsCount, getConfig().getFilename());
        result.complete();
    } catch (final DecodeException e) {
        LOG.warn("cannot read malformed JSON from credentials file [{}]", getConfig().getFilename());
        result.fail(e);
    }
    return result.future();
}
 
Example 2
Source File: FileBasedRegistrationService.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
private Future<Void> addAll(final Buffer deviceIdentities) {

        final Promise<Void> result = Promise.promise();
        try {
            int deviceCount = 0;
            final JsonArray allObjects = deviceIdentities.toJsonArray();
            for (final Object obj : allObjects) {
                if (obj instanceof JsonObject) {
                    deviceCount += addDevicesForTenant((JsonObject) obj);
                }
            }
            LOG.info("successfully loaded {} device identities from file [{}]", deviceCount, getConfig().getFilename());
            result.complete();
        } catch (final DecodeException e) {
            LOG.warn("cannot read malformed JSON from device identity file [{}]", getConfig().getFilename());
            result.fail(e);
        }
        return result.future();
    }