为什么?错误:无法弄清楚如何将此字段保存到数据库中



我遇到了一个傻瓜问题
我收到了来自服务器的响应

data class AddressResponse(
@SerializedName("message") val responseMessage: String,
@SerializedName("success") val success: Int,
@SerializedName("status") val status: Int,
@SerializedName("data") val data: Data
) {
data class Data(
@SerializedName("id") val addressId: Long,
@SerializedName("status") val status: Int?,
@TypeConverters( CommunicationPropertiesConverter::class )
@SerializedName("communication_properties") val communicationProperties: AddAddressRequest.CommunicationProperties?,   
@SerializedName("more_information") val moreInformation: String?                                           
) {
data class CommunicationProperties(
@SerializedName("par1") var par1: Boolean,
@SerializedName("par2") val par2: Boolean,
@SerializedName("par3") val par3: Boolean,
@SerializedName("par4") val par4: Boolean
)
}
}

我使用房间,我有实体类

@Entity(tableName = "db_address")
data class DbAddress(
@PrimaryKey @ColumnInfo(name = COLUMN_ID) val id: Long,
@ColumnInfo(name = COLUMN_STATUS) val status: Int?,
@TypeConverters(CommunicationPropertiesConverter::class)
@ColumnInfo(name = COLUMN_COMM_PROPS) val communicationProperties: AddressResponse.Data.CommunicationProperties,
@ColumnInfo(name = COLUMN_MORE_INFO) val moreInfo: String?
) 

我有一个转换器一组注释@TypeConverters&TypeConverter

class CommunicationPropertiesConverter {
private val gson = Gson()
@TypeConverter
fun toCommunicationProperties(mString: String?): AddressResponse.Data.CommunicationProperties {
if (mString.isNullOrEmpty())
return AddressResponse.Data.CommunicationProperties(par1 = false, par2 = false, par3 = false, par4 = false)
val listType = object : TypeToken<AddressResponse.Data.CommunicationProperties>(){}.type
return gson.fromJson(mString, listType)
}
@TypeConverter
fun fromCommunicationProperties(properties: AddressResponse.Data.CommunicationProperties?): String {
if (properties == null)
return "0000"
return gson.toJson(properties)
}
}

但我还是收到一个错误

错误:无法找出如何将此字段保存到数据库中。你可以考虑为它添加一个类型转换器私人决赛。。。AddressResponse。数据CommunicationProperties CommunicationProperties=空

,但我添加了转换器到";基元";型

为什么?我忘了什么?

我遇到了类似的问题,对我有效的是用@Embedded注释该字段(具有自定义类型(。就我而言,我甚至不再需要类型转换器了。

相关内容

最新更新