mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
some organisation, Base32 password generator
This commit is contained in:
43
src/net/torvald/terrarum/utils/JsonWriter.kt
Normal file
43
src/net/torvald/terrarum/utils/JsonWriter.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package net.torvald.terrarum.utils
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-04.
|
||||
*/
|
||||
object JsonWriter {
|
||||
|
||||
/**
|
||||
* serialise a class to the file as JSON, using Google GSON.
|
||||
*
|
||||
* @param c: a class
|
||||
* @param path: path to write a file
|
||||
*/
|
||||
@Throws(java.io.IOException::class)
|
||||
fun writeToFile(c: Any, path: String) {
|
||||
val classElem = com.google.gson.Gson().toJsonTree(c)
|
||||
val jsonString = classElem.toString()
|
||||
val writer = java.io.FileWriter(path)
|
||||
writer.write(jsonString)
|
||||
writer.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* serialise JsonObject to the file as JSON, using Google GSON.
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param path: path to write a file
|
||||
*/
|
||||
@Throws(java.io.IOException::class)
|
||||
fun writeToFile(jsonObject: com.google.gson.JsonObject, path: String) {
|
||||
val writer = java.io.FileWriter(path)
|
||||
writer.write(jsonObject.toString())
|
||||
writer.close()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user