Example usage for io.vertx.core.json JsonObject mapTo

List of usage examples for io.vertx.core.json JsonObject mapTo

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject mapTo.

Prototype

public <T> T mapTo(Class<T> type) 

Source Link

Document

Instantiate a Java object from a JsonObject.

Usage

From source file:docoverride.json.Examples.java

License:Open Source License

public void mapToPojo(HttpServerRequest request) {
    request.bodyHandler(buff -> {/*from   w w  w  .  j a v a  2  s .c om*/
        JsonObject jsonObject = buff.toJsonObject();
        User javaObject = jsonObject.mapTo(User.class);
    });
}

From source file:org.eclipse.hono.deviceregistry.FileBasedTenantService.java

License:Open Source License

private void addTenant(final JsonObject tenant) {

    try {// w ww .  jav  a 2  s .  co  m
        final TenantObject tenantObject = tenant.mapTo(TenantObject.class);
        log.debug("loading tenant [{}]", tenantObject.getTenantId());
        tenants.put(tenantObject.getTenantId(), tenantObject);
    } catch (IllegalArgumentException e) {
        log.warn("cannot deserialize tenant", e);
    }
}

From source file:org.eclipse.hono.deviceregistry.FileBasedTenantService.java

License:Open Source License

/**
 * Adds a tenant.//  www.  j a va 2 s.  com
 *
 * @param tenantId The identifier of the tenant.
 * @param tenantSpec The information to register for the tenant.
 * @return The outcome of the operation indicating success or failure.
 * @throws NullPointerException if any of the parameters are {@code null}.
 */
public TenantResult<JsonObject> add(final String tenantId, final JsonObject tenantSpec) {

    Objects.requireNonNull(tenantId);
    Objects.requireNonNull(tenantSpec);

    if (tenants.containsKey(tenantId)) {
        return TenantResult.from(HttpURLConnection.HTTP_CONFLICT);
    } else {
        try {
            final TenantObject tenant = tenantSpec.mapTo(TenantObject.class);
            tenant.setTenantId(tenantId);
            final TenantObject conflictingTenant = getByCa(tenant.getTrustedCaSubjectDn());
            if (conflictingTenant != null) {
                // we are trying to use the same CA as an already existing tenant
                return TenantResult.from(HttpURLConnection.HTTP_CONFLICT);
            } else {
                tenants.put(tenantId, tenant);
                dirty = true;
                return TenantResult.from(HttpURLConnection.HTTP_CREATED);
            }
        } catch (IllegalArgumentException e) {
            return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST);
        }
    }
}

From source file:org.eclipse.hono.deviceregistry.FileBasedTenantService.java

License:Open Source License

/**
 * Updates a tenant./*from w  ww  . ja v  a  2s .  c  om*/
 *
 * @param tenantId The identifier of the tenant.
 * @param tenantSpec The information to update the tenant with.
 * @return The outcome of the operation indicating success or failure.
 * @throws NullPointerException if any of the parameters are {@code null}.
 */
public TenantResult<JsonObject> update(final String tenantId, final JsonObject tenantSpec) {

    Objects.requireNonNull(tenantId);
    Objects.requireNonNull(tenantSpec);

    if (getConfig().isModificationEnabled()) {
        if (tenants.containsKey(tenantId)) {
            try {
                final TenantObject tenant = tenantSpec.mapTo(TenantObject.class);
                tenant.setTenantId(tenantId);
                final TenantObject conflictingTenant = getByCa(tenant.getTrustedCaSubjectDn());
                if (conflictingTenant != null && !tenantId.equals(conflictingTenant.getTenantId())) {
                    // we are trying to use the same CA as another tenant
                    return TenantResult.from(HttpURLConnection.HTTP_CONFLICT);
                } else {
                    tenants.put(tenantId, tenant);
                    dirty = true;
                    return TenantResult.from(HttpURLConnection.HTTP_NO_CONTENT);
                }
            } catch (IllegalArgumentException e) {
                return TenantResult.from(HttpURLConnection.HTTP_BAD_REQUEST);
            }
        } else {
            return TenantResult.from(HttpURLConnection.HTTP_NOT_FOUND);
        }
    } else {
        return TenantResult.from(HttpURLConnection.HTTP_FORBIDDEN);
    }
}