Hi guys, I'm using moshi to deserialize JSON back ...
# getting-started
z
Hi guys, I'm using moshi to deserialize JSON back into a Kotlin data class which looks like this
Copy code
data class Response<out T>(
        @Json(name = "success") val success: Boolean,
        @Json(name = "data") val data: T
) {
    init {
        if (!success) {
            throw RuntimeException("Failed...")
        }
    }
}
I think this is the line where moshi instantiates the object
Object[] args = null; return (T) constructor.newInstance(args);
https://github.com/square/moshi/blob/master/moshi/src/main/java/com/squareup/moshi/ClassFactory.java#L44 My issue is that the init method doesn't get called. Can anyone explain why? Am I doing something wrong?
👍 1