Search in sources :

Example 41 with JsonArray

use of com.bluenimble.platform.json.JsonArray in project serverless by bluenimble.

the class YamlPrinter method printObject.

private void printObject(JsonObject object, int indent, boolean startEndln) throws IOException {
    if (Json.isNullOrEmpty(object)) {
        return;
    }
    int counter = 0;
    Iterator<String> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        if (startEndln || counter > 0) {
            endln();
            print(key, indent, DataType.Key);
        } else {
            print(key, 0, DataType.Key);
        }
        counter++;
        print(Colon, DataType.Colon);
        Object value = object.get(key);
        if (value instanceof JsonObject) {
            printObject((JsonObject) value, indent + 1, true);
        } else if (value instanceof JsonArray) {
            printArray((JsonArray) value, indent + 1);
        } else {
            String sv = String.valueOf(value);
            int indexOfEndLn = sv.indexOf(Lang.ENDLN);
            if (indexOfEndLn < 0) {
                print(String.valueOf(value), 0, DataType.Value);
            } else {
                print(Lang.PIPE, 0, DataType.Pipe);
                String[] aSv = Lang.split(sv, Lang.ENDLN);
                for (String s : aSv) {
                    endln();
                    print(s, indent + 1, DataType.Value);
                }
            }
        }
    }
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) JsonObject(com.bluenimble.platform.json.JsonObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 42 with JsonArray

use of com.bluenimble.platform.json.JsonArray in project serverless by bluenimble.

the class YamlPrinter method printArray.

private void printArray(JsonArray array, int indent) throws IOException {
    for (int i = 0; i < array.count(); i++) {
        Object value = array.get(i);
        endln();
        indent(indent);
        print(Dash, DataType.Dash);
        if (value instanceof JsonObject) {
            printObject((JsonObject) value, indent + 1, false);
        } else if (value instanceof JsonArray) {
            printArray((JsonArray) value, indent);
        } else {
            print(String.valueOf(value), 0, DataType.Value);
        }
    }
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) JsonObject(com.bluenimble.platform.json.JsonObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Aggregations

JsonArray (com.bluenimble.platform.json.JsonArray)42 JsonObject (com.bluenimble.platform.json.JsonObject)37 DatabaseObject (com.bluenimble.platform.db.DatabaseObject)9 Map (java.util.Map)8 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)6 ApiSpace (com.bluenimble.platform.api.ApiSpace)5 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)5 Database (com.bluenimble.platform.db.Database)5 IOException (java.io.IOException)5 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)4 ApiAuthenticationException (com.bluenimble.platform.api.security.ApiAuthenticationException)4 CommandExecutionException (com.bluenimble.platform.cli.command.CommandExecutionException)4 DefaultCommandResult (com.bluenimble.platform.cli.command.impls.DefaultCommandResult)4 ApiService (com.bluenimble.platform.api.ApiService)3 DescribeOption (com.bluenimble.platform.api.DescribeOption)3 DatabaseException (com.bluenimble.platform.db.DatabaseException)3 JsonQuery (com.bluenimble.platform.db.query.impls.JsonQuery)3 KeyPair (com.bluenimble.platform.security.KeyPair)3 ArrayList (java.util.ArrayList)3 ApiOutput (com.bluenimble.platform.api.ApiOutput)2