e: 错误: [ObjectBox] Relation target class 'Long' defined in class 'LocalMessage' could not be foun...

使用ObjectBox时遇到的迷之问题,看到这个提示,怎么检查那个类都是加了@Entity注解的。
发生原因是:类里定义了ObjectBox不能理解的字段,比如var atIds: MutableList = mutableListOf(),要写个转换类加上去

    @Convert(converter = LongList2StringConverter::class, dbType = String::class)
    var atIds: MutableList = mutableListOf()
)

class LongList2StringConverter : PropertyConverter, String> {
    override fun convertToDatabaseValue(entityProperty: MutableList?): String {
        return if (entityProperty.isNullOrEmpty()) {
            "[]"
        } else {
            val jsa = JSONArray()
            entityProperty.forEach {
                jsa.put(it)
            }
            jsa.toString()
        }
    }

    override fun convertToEntityProperty(databaseValue: String?): MutableList {
        val result = mutableListOf()
        return if (databaseValue.isNullOrEmpty()) {
            result
        } else {
            val jsa = JSONArray(databaseValue)
            for (i in 0 until jsa.length()) {
                result.add(jsa[i] as Long)
            }
            result
        }
    }

}

你可能感兴趣的:(e: 错误: [ObjectBox] Relation target class 'Long' defined in class 'LocalMessage' could not be foun...)