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] kotlin jdk 21.0.2 情况下JSONWriter.Feature.WriteEnumsUsingName不生效 #2276

Closed
ganweiming opened this issue Feb 28, 2024 · 9 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@ganweiming
Copy link

问题描述

fastjson 2.0.47 , kotlin jdk 21.0.2 情况下JSONWriter.Feature.WriteEnumsUsingName不生效
jdk 1.8情况下正常生效

环境信息

请填写以下信息:

  • JDK信息: [e.g.:Openjdk 21.0.2]
  • 版本信息:[e.g.:Fastjson2 2.0.47

重现步骤

  1. 定义枚举
    enum class RegistrationStatusEnum {
    @JSONField(name = "Accepted")
    ACCEPTED,
    @JSONField(name = "Pending")
    PENDING,
    @JSONField(name = "Rejected")
    REJECTED
    }

  2. 输出枚举
    println("Enum Result: " + RegistrationStatusEnum.PENDING.toJSONString(features = arrayOf(JSONWriter.Feature.WriteEnumsUsingName)))

  3. 输出结果"PENDING"

期待的正确结果

jdk 1.8情况下会正常输出"Pending"
企业微信截图_17090940529913
企业微信截图_17090941021717
企业微信截图_17090941082602

@ganweiming ganweiming added the bug Something isn't working label Feb 28, 2024
@rowstop
Copy link
Contributor

rowstop commented Feb 28, 2024

这个 usingName 是指 Enum.name()

@ganweiming
Copy link
Author

这个 usingName 是指 Enum.name()

但是WriteEnumsUsingName在jdk 1.8中会使用@JSONField中的name属性输出

@rowstop
Copy link
Contributor

rowstop commented Feb 28, 2024

这个 usingName 是指 Enum.name()

但是WriteEnumsUsingName在jdk 1.8中会使用@JSONField中的name属性输出

🤔表现不一致?这是个问题

@ganweiming
Copy link
Author

这个 usingName 是指 Enum.name()

但是WriteEnumsUsingName在jdk 1.8中会使用@JSONField中的name属性输出

🤔表现不一致?这是个问题

是的, 表现不一致才提出的issue

@wenshao
Copy link
Member

wenshao commented Mar 2, 2024

  @Test
    fun test() {
        var str = JSON.toJSONString(Type.ACCEPTED, JSONWriter.Feature.WriteEnumsUsingName)
        assertEquals("\"Accepted\"", str)
        assertEquals(Type.ACCEPTED, JSON.parseObject(str, Type::class.java))
    }

    enum class Type {
        @JSONField(name = "Accepted")
        ACCEPTED,
        @JSONField(name = "Pending")
        PENDING,
        @JSONField(name = "Rejected")
        REJECTED
    }

问题没有重现啊

wenshao added a commit that referenced this issue Mar 2, 2024
@ganweiming
Copy link
Author

var str = JSON.toJSONString(Type.ACCEPTED, JSONWriter.Feature.WriteEnumsUsingName)

jdk 17以上的版本打印输出的为"ACCEPTED", 预期输出为"Accepted"

@wenshao
Copy link
Member

wenshao commented Mar 17, 2024

我测试过JDK 17也是对的啊

@wenshao wenshao added this to the 2.0.49 milestone Apr 6, 2024
@wenshao wenshao added the fixed label Apr 6, 2024
@wenshao
Copy link
Member

wenshao commented Apr 6, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/
问题已修复,请帮忙用2.0.49-SNAPSHOT验证,2.0.49版本预计在月底发布

@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

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

@wenshao wenshao closed this as completed Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants