io.appwrite.extensions.JsonExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-for-kotlin Show documentation
Show all versions of sdk-for-kotlin Show documentation
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Kotlin SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
package io.appwrite.extensions
import com.google.gson.Gson
val gson = Gson()
fun Any.toJson(): String =
gson.toJson(this)
fun String.fromJson(clazz: Class): T =
gson.fromJson(this, clazz)
inline fun String.fromJson(): T =
gson.fromJson(this, T::class.java)
fun Any.jsonCast(to: Class): T =
toJson().fromJson(to)
inline fun Any.jsonCast(): T =
toJson().fromJson(T::class.java)
fun Any.tryJsonCast(to: Class): T? = try {
toJson().fromJson(to)
} catch (ex: Exception) {
ex.printStackTrace()
null
}
inline fun Any.tryJsonCast(): T? = try {
toJson().fromJson(T::class.java)
} catch (ex: Exception) {
ex.printStackTrace()
null
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy