Skip to content

Instantly share code, notes, and snippets.

@manoj-mili
Created March 24, 2022 12:23
Show Gist options
  • Save manoj-mili/d9bd5213f1a4f63b815a0898bda92ae3 to your computer and use it in GitHub Desktop.
Save manoj-mili/d9bd5213f1a4f63b815a0898bda92ae3 to your computer and use it in GitHub Desktop.
abstract class IConfigProvider {
abstract fun getString(key: String): String
abstract fun getBoolean(key: String): Boolean
abstract fun getDouble(key: String): Double
abstract fun getLong(key: String): Long
abstract fun getInt(key: String): Int
inline fun <reified T> dataFromJson(data: String?): T? {
var configData: T? = null
try {
configData = Gson().fromJson(
data,
object : TypeToken<T?>() {}.type
)
} catch (e: JsonParseException) {
e.printStackTrace()
}
return configData
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment