Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] toJSONString() 时似乎会忽略 Boolean 类型的属性 #587

Closed
TigerBeanst opened this issue Jul 27, 2022 · 2 comments
Closed

[BUG] toJSONString() 时似乎会忽略 Boolean 类型的属性 #587

TigerBeanst opened this issue Jul 27, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@TigerBeanst
Copy link

TigerBeanst commented Jul 27, 2022

问题描述

toJSONString() 时似乎会忽略 Boolean 类型的属性

环境信息

请填写以下信息:

  • OS信息: Android 12
  • JDK信息: Android Default JDK: 11.0.13
  • 版本信息:fastjson2-kotlin:2.0.10.android

重现步骤

	@Test
    fun testToJSONString(){
        data class BackupMMKV(val mmkvKey: String, val mmkvValue: Boolean)
        val mmkvList = mutableListOf<BackupMMKV>()
        mmkvList.add(BackupMMKV("test1",true))
        mmkvList.add(BackupMMKV("test2",false))
        val json = mmkvList.toJSONString()
        println(json)
    }

期待的正确结果

[{"mmkvKey":"test1","mmkvValue":true},{"mmkvKey":"test2","mmkvValue":false}]

实际输出

[{"mmkvKey":"test1"},{"mmkvKey":"test2"}]

额外

将 mmkvValue 修改为 Int 类型的话,是可以正常包含在输出的 Json 里的

@TigerBeanst TigerBeanst added the bug Something isn't working label Jul 27, 2022
@TigerBeanst
Copy link
Author

似乎会因为未知原因吞掉 mmkvValue 这个字段名,我顺手改成 isSuccess 后能输出了……不过是 success

wenshao added a commit that referenced this issue Jul 28, 2022
fix: serialization of boolean type (Getter) in kotlin #587
@wenshao wenshao added this to the 2.0.11 milestone Jul 28, 2022
@wenshao
Copy link
Member

wenshao commented Aug 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants