You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
我的kotlin类: class User { val map = mapOf(1 to 2, "a" to "a", 3f to 3f) }
环境信息
AndroidStudio
重现步骤
val user = User()
val bytes = JSONB.toBytes(user)
相关日志输出
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.writeJSONB(ObjectWriterImplMap.java:214)
at com.alibaba.fastjson2.writer.FieldWriterObject.write(FieldWriterObject.java:196)
问题描述
我的kotlin类:
class User { val map = mapOf(1 to 2, "a" to "a", 3f to 3f) }
环境信息
AndroidStudio
重现步骤
val user = User()
val bytes = JSONB.toBytes(user)
相关日志输出
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.writeJSONB(ObjectWriterImplMap.java:214)
at com.alibaba.fastjson2.writer.FieldWriterObject.write(FieldWriterObject.java:196)
附加信息
我看了一下源码,发现我的key是int,但是在 ObjectWriterImplMap 第124行,发现是这样子实现的:
if (entryKey instanceof String || (contextFeatures & JSONWriter.Feature.WriteClassName.mask) == 0) {
String key = (String) entryKey;
xxxx
}
这里爆出的类型转换失败
The text was updated successfully, but these errors were encountered: