apatrida
09/29/2015, 12:06 PMpublic inline fun <reified T: Any> String.toEntity(): T {
return Utils.getGsonInstance().fromJson(this, typeRef<T>().type)
}
public inline fun <reified T: Any> typeRef(): TypeReference<T> = object:TypeReference<T>(){}
public abstract class TypeReference<T> protected constructor() {
public val type: Type by lazy {
javaClass.getGenericSuperclass() let { superClass ->
if (superClass is Class<*>) {
throw IllegalArgumentException("Internal error: TypeReference constructed without actual type information")
}
(superClass as ParameterizedType).getActualTypeArguments()[0]
}
}
}