地图对象的 Kotlin 地图序列化和反序列化错误 class

Kotlin Map Serialization and Deserialization error class with map objects

我正在尝试创建序列化和反序列化对象。我是这样做的:

   var mapper = ObjectMapper()

   var stringTest =   mapper.writeValueAsString(stringContainsObjectFilter);
    
   val raw: Any = mapper.readValue(stringTest, Any::class.java)
   val filtersFromString = mapper.convertValue(raw, ObjectFilter::class.java)

   val objectFilters = ObjectFilter()
   quoteFilters.rosterLine= filtersFromString.rosterLine
   quoteFilters.outOfPocketMax = filtersFromString.outOfPocketMax
   quoteFilters.cost = filtersFromString.cost

这是我要序列化和反序列化的class

open  class ObjectFilter{

    var rosterLine: Map<RosterEnum, List<Int>>? = null

    var outOfPocketMax: Map<String?, List<Int>>? = null

    var monthlyCost: List<MonthlyCost>? = null

}

但我收到以下消息:

"Response[ObjectFilters]; could not unconvert attribute"

有人可以帮帮我吗?我一直在尝试解决它但没有结果:(

我找到了解决方案,这就是我所做的并且有效:

val rawResult = mapper.convertValue(mapper.readValue(string, Any::class.java), Any::class.java)
        val filtersFromString = rawResult  as? ObjectFilter ?: ObjectFilter()