Search in sources :

Example 6 with JsonArray

use of com.google.gson.JsonArray in project disunity by ata4.

the class JsonTablePrinter method tableToJson.

private JsonArray tableToJson(Table<Integer, Integer, Object> table, Gson gson) {
    JsonArray jsonTable = new JsonArray();
    table.rowMap().forEach((rk, r) -> {
        if (rk == 0) {
            return;
        }
        JsonObject jsonRow = new JsonObject();
        table.columnMap().forEach((ck, c) -> {
            String key = String.valueOf(table.get(0, ck)).toLowerCase();
            Object value = table.get(rk, ck);
            jsonRow.add(key, gson.toJsonTree(value));
        });
        jsonTable.add(jsonRow);
    });
    JsonObject jsonRoot = new JsonObject();
    if (file != null) {
        jsonRoot.add("file", new JsonPrimitive(file.toString()));
    }
    return jsonTable;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject)

Example 7 with JsonArray

use of com.google.gson.JsonArray in project disunity by ata4.

the class AssetTypes method printJson.

private void printJson(Path file, TypeTree<? extends Type> typeTree) {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonObject jsonTypeTree = new JsonObject();
    jsonTypeTree.addProperty("file", file.toString());
    if (typeTree.embedded()) {
        JsonArray jsonTypes = new JsonArray();
        typeTree.typeMap().forEach((path, typeRoot) -> {
            JsonObject jsonTypeNode = new JsonObject();
            jsonTypeNode.addProperty("pathID", path);
            jsonTypeNode.addProperty("classID", typeRoot.classID());
            if (typeRoot.scriptID() != null) {
                jsonTypeNode.addProperty("scriptID", typeRoot.scriptID().toString());
            }
            if (typeRoot.oldTypeHash() != null) {
                jsonTypeNode.addProperty("oldTypeHash", typeRoot.oldTypeHash().toString());
            }
            jsonTypeNode.add("nodes", typeNodeToJson(typeRoot.nodes(), gson));
            jsonTypes.add(jsonTypeNode);
        });
        jsonTypeTree.add("types", jsonTypes);
    }
    gson.toJson(jsonTypeTree, output());
}
Also used : JsonArray(com.google.gson.JsonArray) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject)

Example 8 with JsonArray

use of com.google.gson.JsonArray in project iosched by google.

the class DataModelTest method testExtractRooms.

/**
   * Test method for {@link com.google.iosched.model.DataExtractor#extractRooms(com.google.iosched.model.JsonDataSources)}.
   */
@Test
public void testExtractRooms() {
    JsonArray rooms = new DataExtractor(false).extractRooms(sources);
    assertEquals(8, rooms.size());
    JsonObject firstRoom = rooms.get(0).getAsJsonObject();
    String roomName = firstRoom.get(OutputJsonKeys.Rooms.name.name()).getAsString();
    assertEquals(true, roomName.startsWith("Room "));
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 9 with JsonArray

use of com.google.gson.JsonArray in project iosched by google.

the class DataCheck method clone.

private JsonObject clone(JsonObject source) {
    JsonObject dest = new JsonObject();
    for (Map.Entry<String, JsonElement> entry : source.entrySet()) {
        JsonArray values = entry.getValue().getAsJsonArray();
        JsonArray cloned = new JsonArray();
        cloned.addAll(values);
        dest.add(entry.getKey(), cloned);
    }
    return dest;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with JsonArray

use of com.google.gson.JsonArray in project iosched by google.

the class DataCheck method checkUsingPredicator.

public void checkUsingPredicator(CheckResult result, JsonObject oldData, JsonObject newData, Enum<?> entityType, Enum<?> entityKey, EntityValidator predicate) {
    HashMap<String, JsonObject> oldMap = new HashMap<String, JsonObject>();
    HashMap<String, JsonObject> newMap = new HashMap<String, JsonObject>();
    JsonArray oldArray = getAsArray(oldData, entityType);
    JsonArray newArray = getAsArray(newData, entityType);
    if (oldArray != null)
        for (JsonElement el : oldArray) {
            JsonObject obj = (JsonObject) el;
            oldMap.put(get(obj, entityKey).getAsString(), obj);
        }
    if (newArray != null)
        for (JsonElement el : newArray) {
            JsonObject obj = (JsonObject) el;
            newMap.put(get(obj, entityKey).getAsString(), obj);
        }
    for (String id : oldMap.keySet()) {
        predicate.evaluate(result, entityType.name(), oldMap.get(id), newMap.get(id));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonArray (com.google.gson.JsonArray)424 JsonObject (com.google.gson.JsonObject)290 JsonElement (com.google.gson.JsonElement)167 JsonPrimitive (com.google.gson.JsonPrimitive)118 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)57 ArrayList (java.util.ArrayList)50 HashMap (java.util.HashMap)34 Map (java.util.Map)34 Gson (com.google.gson.Gson)22 IOException (java.io.IOException)17 Test (org.junit.Test)16 Type (java.lang.reflect.Type)12 List (java.util.List)11 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6