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] 2.0.26使用 SupportAutoType 反序列化时,如果存在使用枚举类为 key 的 map 则总会失败 #1324

Closed
huangluyu opened this issue Apr 6, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@huangluyu
Copy link

问题描述

使用 SupportAutoType 反序列化时,如果存在使用枚举类为 key 的 map 则总会失败
2.0.17 没有这个问题,2.0.26 会有,没有深究具体出现的版本

重现步骤

import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONReader

enum TestEnum {
    x1,
    x2
}

class Test {

    Map<TestEnum, Integer> map;
}


String json = "{\"map\": {\"x1\": 1}}"
JSON.parseObject(json, Test.class, JSONReader.Feature.SupportAutoType)

相关日志输出

com.alibaba.fastjson2.JSONException: not support name x1
	at com.alibaba.fastjson2.reader.ObjectReaderImplMapTyped.readObject(ObjectReaderImplMapTyped.java:315)
	at com.alibaba.fastjson2.reader.ORG_1_2_Test.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:848)
@huangluyu huangluyu added the bug Something isn't working label Apr 6, 2023
@lorna1
Copy link

lorna1 commented Apr 6, 2023

使用boolean值作为map key 也会出现同样问题,例如
"cases": {
"true": "node119",
"false": "node120"
}

报错: not support name true

@wenshao wenshao added this to the 2.0.27 milestone Apr 7, 2023
@wenshao wenshao added the fixed label Apr 7, 2023
wenshao added a commit that referenced this issue Apr 7, 2023
@wenshao
Copy link
Member

wenshao commented Apr 8, 2023

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

@wenshao wenshao closed this as completed Apr 8, 2023
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