-
Notifications
You must be signed in to change notification settings - Fork 495
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
Comments
这个 usingName 是指 Enum.name() |
但是WriteEnumsUsingName在jdk 1.8中会使用@JSONField中的name属性输出 |
🤔表现不一致?这是个问题 |
是的, 表现不一致才提出的issue |
@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
} 问题没有重现啊 |
jdk 17以上的版本打印输出的为"ACCEPTED", 预期输出为"Accepted" |
我测试过JDK 17也是对的啊 |
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/ |
问题描述
fastjson 2.0.47 , kotlin jdk 21.0.2 情况下JSONWriter.Feature.WriteEnumsUsingName不生效
jdk 1.8情况下正常生效
环境信息
请填写以下信息:
重现步骤
定义枚举
enum class RegistrationStatusEnum {
@JSONField(name = "Accepted")
ACCEPTED,
@JSONField(name = "Pending")
PENDING,
@JSONField(name = "Rejected")
REJECTED
}
输出枚举
println("Enum Result: " + RegistrationStatusEnum.PENDING.toJSONString(features = arrayOf(JSONWriter.Feature.WriteEnumsUsingName)))
输出结果"PENDING"
期待的正确结果
jdk 1.8情况下会正常输出"Pending"
The text was updated successfully, but these errors were encountered: