Created
November 15, 2018 17:08
-
-
Save MikeFot/374491dbcc9b9551254799f808cbb0b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.Gson | |
abstract class BaseJsonTest { | |
val serializer = Serializer() | |
inner class Serializer { | |
private val gson = Gson() | |
fun <T> deserialize(payload: String, clazz: Class<T>) = gson.fromJson(payload, clazz)!! | |
fun <T> serialize(item: T, clazz: Class<T>) = gson.toJson(item, clazz)!! | |
} | |
abstract fun shouldSerialize() | |
abstract fun getPayload(): String | |
inline fun <reified T> serialize(item: T) = serializer.serialize(item, T::class.java) | |
inline fun <reified T> deserialize(payload: String) = | |
serializer.deserialize(payload, T::class.java) | |
inline fun <reified T> deserialize() = deserialize<T>(getPayload()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment