use of net.anweisen.utilities.common.config.document.GsonDocument in project Utility by anweisen.
the class Document method readJsonArrayFile.
@Nonnull
@CheckReturnValue
static List<Document> readJsonArrayFile(@Nonnull Path file) {
try {
JsonArray array = GsonDocument.GSON.fromJson(FileUtils.newBufferedReader(file), JsonArray.class);
if (array == null)
return new ArrayList<>();
List<Document> documents = new ArrayList<>(array.size());
array.forEach(element -> documents.add(new GsonDocument(element.getAsJsonObject())));
return documents;
} catch (IOException ex) {
throw new WrappedException(ex);
}
}
use of net.anweisen.utilities.common.config.document.GsonDocument in project Utility by anweisen.
the class DocumentTypeAdapter method write.
@Override
public void write(@Nonnull Gson gson, @Nonnull JsonWriter writer, @Nonnull Document document) throws IOException {
if (document instanceof GsonDocument) {
GsonDocument gsonDocument = (GsonDocument) document;
TypeAdapters.JSON_ELEMENT.write(writer, gsonDocument.getJsonObject());
return;
}
Document copiedDocument = document.copyJson();
if (copiedDocument instanceof GsonDocument) {
GsonDocument gsonDocument = (GsonDocument) copiedDocument;
TypeAdapters.JSON_ELEMENT.write(writer, gsonDocument.getJsonObject());
return;
}
GsonDocument gsonDocument = new GsonDocument(document.values());
TypeAdapters.JSON_ELEMENT.write(writer, gsonDocument.getJsonObject());
}
Aggregations