我正在尝试在 Retrofit 中反序列化此类:
data class Measurement(val id: Long, val value: Float, val dateTime: LocalDateTime, val trashCanId: Long) : Parcelable {
companion object {
@JvmField val CREATOR: Parcelable.Creator<Measurement> = object : Parcelable.Creator<Measurement> {
override fun createFromParcel(source: Parcel): Measurement = Measurement(source)
override fun newArray(size: Int): Array<Measurement?> = arrayOfNulls(size)
}
}
constructor(source: Parcel) : this(source.readLong(), source.readFloat(), source.readSerializable() as LocalDateTime, source.readLong())
override fun describeContents() = 0
override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeLong(id)
dest?.writeFloat(value)
dest?.writeSerializable(dateTime)
dest?.writeLong(trashCanId)
}
}
如您所见,我使用的是 LocalDateTime,它来自 ThreeTen。好吧,我从我的服务器收到这个
{
"id": 1,
"value": 50.6,
"dateTime": {
"hour": 2,
"minute": 6,
"second": 9,
"nano": 0,
"dayOfYear": 308,
"dayOfWeek": "THURSDAY",
"month": "NOVEMBER",
"dayOfMonth": 3,
"year": 2016,
"monthValue": 11,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}
好吧,但是我的 dateTime 始终为Null,所以我相信 Retrofit 不知道如何解析数据,或者我错过了什么?
有什么好的解决方法吗?
任何帮助表示赞赏!