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

#java# 规范 fastjson 编码示例 增补修订建议 #12

Open
k4n5ha0 opened this issue May 24, 2021 · 0 comments
Open

#java# 规范 fastjson 编码示例 增补修订建议 #12

k4n5ha0 opened this issue May 24, 2021 · 0 comments

Comments

@k4n5ha0
Copy link

k4n5ha0 commented May 24, 2021

  • fastjson 版本应不低于1.2.76
  • 如果不需要快速存储数据则应开启 fastjson 的 safeMode 模式
  • 如需使用 fastjson 快速存储数据到redis中应使用 autotype 白名单进行数据存储
// 开启safeMode模式,完全禁用autoType。
1. 在代码中配置
    ParserConfig.getGlobalInstance().setSafeMode(true);
    如果使用new ParserConfig的方式,需要注意单例处理,否则会导致低性能full gc

2. 加上JVM启动参数
    -Dfastjson.parser.safeMode=true

3. 通过fastjson.properties文件配置。
    通过类路径的fastjson.properties文件配置,配置方式如下:
    fastjson.parser.safeMode=true

// 添加autotype白名单,添加白名单有三种方式
1. 在代码中配置,如果有多个包名前缀,分多次addAccept
    ParserConfig.getGlobalInstance().addAccept("com.hyit.pac.client.sdk.dataobject.");

2. 加上JVM启动参数,如果有多个包名前缀,用逗号隔开
    -Dfastjson.parser.autoTypeAccept=com.hyit.pac.client.sdk.dataobject.,com.cainiao. 

3. 通过类路径的fastjson.properties文件配置,如果有多个包名前缀,用逗号隔开safeMode模式
    fastjson.parser.autoTypeAccept=com.hyit.pac.client.sdk.dataobject.,com.cainiao. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant