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

[FEATURE]建议增加一些空值和空流转换时的容错 #389

Closed
leblancvn opened this issue May 31, 2022 · 3 comments
Closed

[FEATURE]建议增加一些空值和空流转换时的容错 #389

leblancvn opened this issue May 31, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@leblancvn
Copy link

请描述您的需求或者改进建议

希望将空字符或者空流转成JSONObject不用报错,而是返回空对象。(2.0.5版本)

请描述你建议的实现方案

一些空值,或者空参数建议不要直接报错,而是返回一个空对象,因为从fastjson迁移到fastjson2时发现一些空参数不能转成JSONObject。

描述您考虑过的替代方案

部分情况下使用parseObject(String text)可以解决空串的问题

附加信息

1.空串转成JSONObject报错(fastjson1.x版本没有问题)。
String whiteConfig = "";
com.alibaba.fastjson2.JSONObject whiteListJson = com.alibaba.fastjson2.JSON.parseObject(whiteConfig, com.alibaba.fastjson2.JSONObject.class);
可以使用parseObject(String text)这个方法,但是最好做一下兼容。

2.使用后的流转换JSONObject报错(fastjson1.x版本没有问题)。
ClassPathResource jsoupWhiteListPathRes = new ClassPathResource("/json/xxx.json");
InputStream whiteConfig = jsoupWhiteListPathRes.getInputStream();
com.alibaba.fastjson2.JSONObject whiteListJson2 = com.alibaba.fastjson2.JSON.parseObject(whiteConfig);
com.alibaba.fastjson2.JSONObject whiteListJson3 = com.alibaba.fastjson2.JSON.parseObject(whiteConfig);

@leblancvn leblancvn added the enhancement New feature or request label May 31, 2022
@wenshao wenshao added this to the 2.0.6 milestone May 31, 2022
@wenshao wenshao added bug Something isn't working and removed enhancement New feature or request labels May 31, 2022
@wenshao
Copy link
Member

wenshao commented May 31, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/

问题已经修复,请帮忙用2.0.6-SNAPSHOT版本验证,2.0.6正式版预计6月5日前发布

@leblancvn
Copy link
Author

好的感谢。

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/

问题已经修复,请帮忙用2.0.6-SNAPSHOT版本验证,2.0.6正式版预计6月5日前发布

好的感谢。

@wenshao
Copy link
Member

wenshao commented Jun 4, 2022

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

@wenshao wenshao closed this as completed Jun 4, 2022
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