``` public inline fun <reified T: Any> Strin...
# getting-started
a
Copy code
public 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]
        }
    }
}