String path = String.format(DATA_FILE_MASK, directory.getPath(),
Character.valueOf(File.separatorChar));
File dataFile = new File(path);
try {
GsonBuilder builder = new GsonBuilder();
WorkerAdapter adapter = new WorkerAdapter();
builder.registerTypeAdapter(WorkerInfo.class, adapter);
Gson serializer = builder
.setPrettyPrinting()
.serializeNulls()
.excludeFieldsWithModifiers(Modifier.STATIC,
Modifier.TRANSIENT).create();
FileOutputStream outputStream = new FileOutputStream(dataFile);
JsonWriter writer = new JsonWriter(new OutputStreamWriter(
outputStream, "UTF-8"));
writer.setSerializeNulls(true);
writer.setIndent(" ");
writer.beginArray();
for (Map.Entry<UUID, WorkerInfo> i : workerStack.entrySet()) {
adapter.setCurrentUUID(i.getKey());
serializer.toJson(i.getValue(), WorkerInfo.class, writer);
}
writer.endArray();
writer.close();
outputStream.close();