Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] Kotlin序列化报错 #440

Closed
xiaolei123 opened this issue Jun 8, 2022 · 2 comments
Closed

[BUG] Kotlin序列化报错 #440

xiaolei123 opened this issue Jun 8, 2022 · 2 comments
Labels
bug Something isn't working jsonb kotlin
Milestone

Comments

@xiaolei123
Copy link

问题描述

我的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
}

这里爆出的类型转换失败

@xiaolei123 xiaolei123 added the bug Something isn't working label Jun 8, 2022
@wenshao wenshao changed the title [BUG] [BUG] Kotlin序列化报错 Jun 9, 2022
@wenshao
Copy link
Member

wenshao commented Jun 10, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.7-SNAPSHOT/
问题已经重现并修复,请用2.0.7-SNAPSHOT版本验证

@wenshao wenshao added this to the 2.0.7 milestone Jun 10, 2022
@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.7
问题已经修复,请用新版本

@wenshao wenshao closed this as completed Jun 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working jsonb kotlin
Projects
None yet
Development

No branches or pull requests

2 participants