我有一个类
但是使用GSON反序列化后,answers字段为空。
我还尝试将初始化代码放入init{}中,但它仍然为空。使用lazy会抛出一个关于在空对象引用上调用lazy.getValue的异常。
class ThreadComment(
banned: Int,
closed: Int,
comment: String?,
date: String?,
email: String?,
files: ArrayList<File>?,
lasthit: Int,
name: String?,
num: String?,
op: Int,
parent: String?,
postsCount: Int,
sticky: Int,
subject: String?,
tags: String?,
timestamp: Int,
trip: String?) : Comment(banned, closed, comment, date, email, files, lasthit, name, num, op, parent, postsCount, sticky, subject, tags, timestamp, trip) {
val answers: ArrayList<String> = ArrayList()}
父类看起来像
open class Comment(
@com.google.gson.annotations.SerializedName("banned")
val banned: Int = 0,
@com.google.gson.annotations.SerializedName("closed")
val closed: Int = 0,
@com.google.gson.annotations.SerializedName("comment")
val comment: String? = null,
@com.google.gson.annotations.SerializedName("date")
val date: String? = null,
@com.google.gson.annotations.SerializedName("email")
val email: String? = null,
@com.google.gson.annotations.SerializedName("files")
val files: ArrayList<File>? = null,
@com.google.gson.annotations.SerializedName("lasthit")
val lasthit: Int = 0,
@com.google.gson.annotations.SerializedName("name")
val name: String? = null,
@com.google.gson.annotations.SerializedName("num")
val num: String? = null,
@com.google.gson.annotations.SerializedName("op")
val op: Int = 0,
@com.google.gson.annotations.SerializedName("parent")
val parent: String? = null,
@com.google.gson.annotations.SerializedName("posts_count")
val postsCount: Int = 0,
@com.google.gson.annotations.SerializedName("sticky")
val sticky: Int = 0,
@com.google.gson.annotations.SerializedName("subject")
val subject: String? = null,
@com.google.gson.annotations.SerializedName("tags")
val tags: String? = null,
@com.google.gson.annotations.SerializedName("timestamp")
val timestamp: Int = 0,
@com.google.gson.annotations.SerializedName("trip")
val trip: String? = null) : Serializable
但是使用GSON反序列化后,answers字段为空。
![Debugger](https://istack.dev59.com/3ijnL.webp)