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

请教反序列化包含泛型的问题 #28

Closed
lianfuye opened this issue Apr 20, 2022 · 4 comments
Closed

请教反序列化包含泛型的问题 #28

lianfuye opened this issue Apr 20, 2022 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@lianfuye
Copy link

lianfuye commented Apr 20, 2022

Result result = JSON.parseObject(str, new TypeReference<Result>(){});

2.x 中这么使用反序列化(包含泛型)时 IDEA 提示下面的错误,请教 2.x 如何处理这块 ?感谢!

无法解析方法'parseObject(java.lang.String, anonymous com.alibaba.fastjson2.TypeReference<com.william.mall.common.model.Result<com.william.mall.common.model.TestUser>>)'

@wenshao
Copy link
Member

wenshao commented Apr 20, 2022

String str = "{}";

Result result = JSON.parseObject(str, new TypeReference<Result>(){}.getType());
assertNotNull(result);

可以先通过上面的方法解决,下一个版本2.0.2会直接支持传入TypeReference

@wenshao wenshao added this to the 2.0.2 milestone Apr 20, 2022
@wenshao wenshao added the enhancement New feature or request label Apr 20, 2022
@lianfuye
Copy link
Author

thanks 大佬 ~

@wenshao
Copy link
Member

wenshao commented Apr 21, 2022

2.0.2预计5月3日前发布

@wenshao wenshao closed this as completed Apr 21, 2022
@wenshao
Copy link
Member

wenshao commented May 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants