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

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

Introduction

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

Prototype

public Object getValue(String key) 

Source Link

Document

Get the value with the specified key, as an Object with types respecting the limitations of JSON.

Usage

From source file:org.sfs.util.HttpRequestValidationException.java

License:Apache License

private void checkEntity(JsonObject entity) {
    checkArgument(entity.getValue("code") == null, "code is a reserved field");
}

From source file:org.sfs.util.JsonHelper.java

License:Apache License

public static String getField(JsonObject config, String name, String defaultValue) {
    Object value = config.getValue(name);
    return value != null ? value.toString() : defaultValue;
}

From source file:org.sfs.util.JsonHelper.java

License:Apache License

public static String getField(JsonObject config, String name) {
    Object value = config.getValue(name);
    return value != null ? value.toString() : null;
}

From source file:org.sub.bug.BugCRUDServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/* www .ja  v  a 2  s  .co  m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {
        case "saveBug": {
            service.saveBug(json.getJsonObject("bug") == null ? null
                    : new org.sub.bug.entity.Bug(json.getJsonObject("bug")), createHandler(msg));
            break;
        }
        case "retrieveBug": {
            service.retrieveBug((java.lang.String) json.getValue("bugId"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "removeBug": {
            service.removeBug((java.lang.String) json.getValue("bugId"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:org.sub.bug.entity.BugConverter.java

License:Apache License

public static void fromJson(JsonObject json, Bug obj) {
    if (json.getValue("bugDateClosed") instanceof String) {
        obj.setBugDateClosed((String) json.getValue("bugDateClosed"));
    }//from www.  jav  a  2s  .  co  m
    if (json.getValue("bugDateReported") instanceof String) {
        obj.setBugDateReported((String) json.getValue("bugDateReported"));
    }
    if (json.getValue("bugDescription") instanceof String) {
        obj.setBugDescription((String) json.getValue("bugDescription"));
    }
    if (json.getValue("bugDeveloper") instanceof JsonObject) {
        obj.setBugDeveloper(new org.sub.bug.entity.BugDeveloper((JsonObject) json.getValue("bugDeveloper")));
    }
    if (json.getValue("bugId") instanceof String) {
        obj.setBugId((String) json.getValue("bugId"));
    }
    if (json.getValue("bugReporter") instanceof String) {
        obj.setBugReporter((String) json.getValue("bugReporter"));
    }
    if (json.getValue("module") instanceof String) {
        obj.setModule((String) json.getValue("module"));
    }
    if (json.getValue("moduleName") instanceof String) {
        obj.setModuleName((String) json.getValue("moduleName"));
    }
    if (json.getValue("problemLogs") instanceof JsonArray) {
        java.util.ArrayList<org.sub.bug.entity.BugProblemLog> list = new java.util.ArrayList<>();
        json.getJsonArray("problemLogs").forEach(item -> {
            if (item instanceof JsonObject)
                list.add(new org.sub.bug.entity.BugProblemLog((JsonObject) item));
        });
        obj.setProblemLogs(list);
    }
}

From source file:org.sub.bug.entity.BugDeveloperConverter.java

License:Apache License

public static void fromJson(JsonObject json, BugDeveloper obj) {
    if (json.getValue("details") instanceof String) {
        obj.setDetails((String) json.getValue("details"));
    }// w w  w  .ja  v  a 2 s. c  om
    if (json.getValue("developerName") instanceof String) {
        obj.setDeveloperName((String) json.getValue("developerName"));
    }
}

From source file:org.sub.bug.entity.BugProblemLogConverter.java

License:Apache License

public static void fromJson(JsonObject json, BugProblemLog obj) {
    if (json.getValue("logDate") instanceof String) {
        obj.setLogDate((String) json.getValue("logDate"));
    }/*from w  ww.j av a  2 s . c om*/
    if (json.getValue("logDescription") instanceof String) {
        obj.setLogDescription((String) json.getValue("logDescription"));
    }
    if (json.getValue("logWork") instanceof String) {
        obj.setLogWork((String) json.getValue("logWork"));
    }
}

From source file:se.liquidbytes.jel.database.DatabaseConnectionVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//from w ww.  j av  a 2 s.  c  o  m
    switch (action) {
    case "getSite": {
        service.getSite((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getSites": {
        service.getSites(createHandler(msg));
        break;
    }
    case "addSite": {
        service.addSite((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "updateSite": {
        service.updateSite((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "removeSite": {
        service.removeSite((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getUser": {
        service.getUser((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    case "getUserByUsername": {
        service.getUserByUsername((java.lang.String) json.getValue("username"), createHandler(msg));
        break;
    }
    case "getUsers": {
        service.getUsers(createHandler(msg));
        break;
    }
    case "addUser": {
        service.addUser((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "updateUser": {
        service.updateUser((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "removeUser": {
        service.removeUser((java.lang.String) json.getValue("id"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:servicefactories.BasicServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from  www.  jav a  2 s . c o m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "find": {
            service.find((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
            break;
        }
        case "hello": {
            service.hello((java.lang.String) json.getValue("key"), createHandler(msg));
            break;
        }
        case "call": {
            service.call((java.lang.String) json.getValue("key"));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:todo.entity.TodoConverter.java

License:Apache License

public static void fromJson(JsonObject json, Todo obj) {
    if (json.getValue("completed") instanceof Boolean) {
        obj.setCompleted((Boolean) json.getValue("completed"));
    }//w  w  w  .ja  va  2  s  . co  m
    if (json.getValue("id") instanceof Number) {
        obj.setId(((Number) json.getValue("id")).intValue());
    }
    if (json.getValue("incIdWith") instanceof Number) {
        obj.setIncIdWith(((Number) json.getValue("incIdWith")).intValue());
    }
    if (json.getValue("order") instanceof Number) {
        obj.setOrder(((Number) json.getValue("order")).intValue());
    }
    if (json.getValue("title") instanceof String) {
        obj.setTitle((String) json.getValue("title"));
    }
    if (json.getValue("url") instanceof String) {
        obj.setUrl((String) json.getValue("url"));
    }
}