【发布时间】:2017-11-21 04:41:10
【问题描述】:
我正在为 gson 使用@parcelize
这是我的课
@Parcelize
data class CommunityModel(@SerializedName("post") val post: PostModel,
@SerializedName("is_liked") val isLiked: Boolean,
@SerializedName("post_like") val postLike: QuestionModel,
@SerializedName("polling_options") val pollingOptions: List<PollingModel>,
@SerializedName("post_polled") val postPolled: Boolean) : Parcelable
我收到错误Unable to invoke no-args constructor for class. Register an InstanceCreator with Gson for this type may fix this problem.。
但此错误仅出现在较旧的 android 版本(低于 5.0)
我尝试实现默认构造函数:
constructor: this(PostModel(), true, QuestionModel(), emptyList(), true)
但它却给了我java.lang.VerifyError
我正在使用带有rxjava2和gson转换器版本2.3
的retrofit2我的 kotlin 版本是 1.1.51
这是已知的错误吗?还是我做错了什么?
【问题讨论】:
标签: kotlin gson parcelable json-deserialization