Search in sources :

Example 86 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project wcomponents by BorderTech.

the class TreeItemUtil method processJsonToTree.

/**
 * Iterate over the JSON objects to create the tree structure.
 *
 * @param parentNode the parent node
 * @param json the current JSON object
 */
private static void processJsonToTree(final TreeItemIdNode parentNode, final JsonObject json) {
    String id = json.getAsJsonPrimitive("id").getAsString();
    JsonPrimitive expandableJson = json.getAsJsonPrimitive("expandable");
    TreeItemIdNode node = new TreeItemIdNode(id);
    if (expandableJson != null && expandableJson.getAsBoolean()) {
        node.setHasChildren(true);
    }
    parentNode.addChild(node);
    JsonArray children = json.getAsJsonArray("items");
    if (children != null) {
        for (int i = 0; i < children.size(); i++) {
            JsonObject child = children.get(i).getAsJsonObject();
            processJsonToTree(node, child);
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode) JsonObject(com.google.gson.JsonObject)

Example 87 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project blogwt by billy1380.

the class Message method toJson.

@Override
public JsonObject toJson() {
    JsonObject object = super.toJson();
    JsonElement jsonTitle = title == null ? JsonNull.INSTANCE : new JsonPrimitive(title);
    object.add("title", jsonTitle);
    JsonElement jsonBody = body == null ? JsonNull.INSTANCE : new JsonPrimitive(body);
    object.add("body", jsonBody);
    JsonElement jsonClick_action = click_action == null ? JsonNull.INSTANCE : new JsonPrimitive(click_action);
    object.add("click_action", jsonClick_action);
    return object;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 88 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project blogwt by billy1380.

the class Payload method toJson.

@Override
public JsonObject toJson() {
    JsonObject object = super.toJson();
    JsonElement jsonTo = to == null ? JsonNull.INSTANCE : new JsonPrimitive(to);
    object.add("to", jsonTo);
    JsonElement jsonRegistration_ids = JsonNull.INSTANCE;
    if (registration_ids != null) {
        jsonRegistration_ids = new JsonArray();
        for (int i = 0; i < registration_ids.size(); i++) {
            JsonElement jsonRegistration_idsItem = registration_ids.get(i) == null ? JsonNull.INSTANCE : new JsonPrimitive(registration_ids.get(i));
            ((JsonArray) jsonRegistration_ids).add(jsonRegistration_idsItem);
        }
    }
    object.add("registration_ids", jsonRegistration_ids);
    JsonElement jsonCondition = condition == null ? JsonNull.INSTANCE : new JsonPrimitive(condition);
    object.add("condition", jsonCondition);
    JsonElement jsonCollapse_key = collapse_key == null ? JsonNull.INSTANCE : new JsonPrimitive(collapse_key);
    object.add("collapse_key", jsonCollapse_key);
    JsonElement jsonPriority = priority == null ? JsonNull.INSTANCE : new JsonPrimitive(priority.toString());
    object.add("priority", jsonPriority);
    JsonElement jsonContent_available = content_available == null ? JsonNull.INSTANCE : new JsonPrimitive(content_available);
    object.add("content_available", jsonContent_available);
    JsonElement jsonMutable_content = mutable_content == null ? JsonNull.INSTANCE : new JsonPrimitive(mutable_content);
    object.add("mutable_content", jsonMutable_content);
    JsonElement jsonTime_to_live = time_to_live == null ? JsonNull.INSTANCE : new JsonPrimitive(time_to_live);
    object.add("time_to_live", jsonTime_to_live);
    JsonElement jsonRestricted_package_name = restricted_package_name == null ? JsonNull.INSTANCE : new JsonPrimitive(restricted_package_name);
    object.add("restricted_package_name", jsonRestricted_package_name);
    JsonElement jsonDry_run = dry_run == null ? JsonNull.INSTANCE : new JsonPrimitive(dry_run);
    object.add("dry_run", jsonDry_run);
    JsonElement jsonData = data == null ? JsonNull.INSTANCE : data.toJson();
    object.add("data", jsonData);
    JsonElement jsonNotification = notification == null ? JsonNull.INSTANCE : notification.toJson();
    object.add("notification", jsonNotification);
    return object;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 89 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project blogwt by billy1380.

the class WebMessage method toJson.

@Override
public JsonObject toJson() {
    JsonObject object = super.toJson();
    JsonElement jsonIcon = icon == null ? JsonNull.INSTANCE : new JsonPrimitive(icon);
    object.add("icon", jsonIcon);
    return object;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 90 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project blogwt by billy1380.

the class Response method toJson.

@Override
public JsonObject toJson() {
    JsonObject object = super.toJson();
    JsonElement jsonStatus = status == null ? JsonNull.INSTANCE : new JsonPrimitive(status.toString());
    object.add("status", jsonStatus);
    JsonElement jsonError = error == null ? JsonNull.INSTANCE : error.toJson();
    object.add("error", jsonError);
    JsonElement jsonSession = session == null ? JsonNull.INSTANCE : session.toJson();
    object.add("session", jsonSession);
    return object;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)230 JsonObject (com.google.gson.JsonObject)137 JsonArray (com.google.gson.JsonArray)118 JsonElement (com.google.gson.JsonElement)106 Test (org.testng.annotations.Test)56 Test (org.junit.Test)12 Map (java.util.Map)10 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)6 HashMap (java.util.HashMap)5 GsonBuilder (com.google.gson.GsonBuilder)4 JsonParser (com.google.gson.JsonParser)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Type (java.lang.reflect.Type)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2