-
Notifications
You must be signed in to change notification settings - Fork 519
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] parsing ['1'] , ["1.1"] #3276
Comments
@wenshao 由于这次更新改变了对单元素数组的默认操作逻辑,造成了一些线上事故,目前暂时通过降低版本解决了,新版本可以通过设置Feature来恢复老版本的运行逻辑吗 |
为什么会导致故障,可以详细说下么? |
@wenshao 简化后的业务代码如下 public class Test {
@Data
public static class Request { // controller接收请求body的类
private Map<String, String> variables;
}
public static void main(String[] args) throws Throwable {
// 系统配置的变量名对应的数据类型
final Map<String, String> VariableTypeMapping = new LinkedHashMap<>(2, 1.0F, false);
VariableTypeMapping.put("usernames", "StringList"); // 变量‘usernames’的数据类型是List<String>
// 前端调后端接口传入的数据
String apiInput = """
{
"variables": {
"usernames": ["张三"]
}
}
""";
// 后端将前端请求的数据解析为Java对象
Request request = JSON.parseObject(apiInput, Request.class);
for (Map.Entry<String, String> entry : request.variables.entrySet()) {
// 根据变量名“usernames”获取这个变量的数据类型
String dataType = VariableTypeMapping.get(entry.getKey());
if ("StringList".equals(dataType)) {
JSON.parseArray(entry.getValue()); // 2.0.56 版本,这里获取到的数据是‘张三’,而老版本的fastsjon2获取到的是‘["张三"]’
}
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
Integer和Long类型的
["123"]
可以解析,Double无法解析,Character会只保留[
环境信息
The text was updated successfully, but these errors were encountered: