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;
}
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());
}
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 "));
}
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;
}
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));
}
}
Aggregations