fastjson Map的key为object时序列化和反序列化异常

wz8daaqr  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(253)

展示例子如下:

`import com.alibaba.fastjson.JSON
import kotlinx.serialization.Serializable
import java.util.*
import kotlin.collections.HashMap

@serializable
class Project(val name: String, val language: String)

//bug test
fun main(){

val map = HashMap<Any,Any>()
val user = Project("hello", "hello")

map.put(user, user)
val result = JSON.toJSONString(map)

System.out.println(result)

val back = JSON.parseObject(result)

System.out.println(back.keys.size)
back.keys.forEach {
System.out.println(it + " dd ")
}
System.out.println( " ")
}`

凡序列化异常:

Exception in thread "main" java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be cast to java.lang.String
at JSONTestKt.main(JSONTest.kt:31)
at JSONTestKt.main(JSONTest.kt)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题