fastjson2
fastjson2 copied to clipboard
fastjson1.x 兼容版本 2.0.14 调用 JSON.parseArray(jsonData, clazz);出错 无法转换
问题描述
简要描述您碰到的问题。
#584 此项修复 fastjson1.x 更新最新兼容版本2.0.14
测试config属性 JSON.parseArray 依旧还是 null (1.2.x 版本 无误 2.x以上版本 获取确是null)
如图:
环境信息
请填写以下信息:
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.14 1.x兼容版本 ]
重现步骤
如何操作可以重现该问题: #584 详细
- 使用
xxx.xxx
方法 - 输入
...
数据 - 出现
...
错误
//可在此输入示例代码
``` 详细见 #584
测试数据
jsonData :
[{
"__config__": {
"formId": 115,
"visibility": ["pc", "app"],
"pfKey": "select",
"defaultValue": "",
"dataType": "static",
"dictionaryType": "",
"dragDisabled": false,
"label": "所属项目",
"propsUrl": "",
"showLabel": true,
"required": false,
"props": {
"label": "fullName",
"value": "id"
},
"renderKey": 1611127618069,
"tableName": "test_subpackage",
"layout": "colFormItem",
"tagIcon": "icon-ym icon-ym-generator-select",
"tag": "el-select",
"span": 24
},
"__vModel__": "projectS",
"disabled": false,
"placeholder": "请选择",
"__slot__": {
"options": [{
"fullName": "选项一",
"id": "1"
}, {
"fullName": "选项二",
"id": "2"
}]
}
}, {
"__config__": {
"formId": 101,
"visibility": ["pc", "app"],
"pfKey": "depSelect",
"dragDisabled": false,
"label": "所属部门",
"showLabel": true,
"required": false,
"renderKey": 1606979361829,
"tableName": "test_subpackage",
"layout": "colFormItem",
"tagIcon": "icon-ym icon-ym-generator-department",
"changeTag": true,
"tag": "dep-select",
"regList": [],
"span": 12
},
"__vModel__": "depNameA",
"disabled": false,
"placeholder": "请选择"
}, {
"clearable": true,
"__config__": {
"formId": 116,
"visibility": ["pc", "app"],
"pfKey": "userSelect",
"dragDisabled": false,
"label": "填单人",
"trigger": "click",
"showLabel": true,
"required": false,
"tableName": "test_subpackage",
"renderKey": 1652256065583,
"layout": "colFormItem",
"tagIcon": "icon-ym icon-ym-generator-user",
"tag": "user-select",
"regList": [],
"span": 12
},
"multiple": false,
"__vModel__": "applys",
"disabled": false,
"placeholder": "请选择",
"on": {
"change": "({ data, formData, setFormData, setShowOrHide, setRequired, setDisabled, request, getFieldOptions, setFieldOptions }) => {\n // 在此编写代码\n \n}"
}
}, {
"clearable": true,
"prefix-icon": "",
"show-password": false,
"__config__": {
"formId": 118,
"visibility": ["pc", "app"],
"pfKey": "comInput",
"noShow": false,
"dragDisabled": false,
"label": "承包方",
"trigger": "blur",
"showLabel": true,
"required": false,
"tableName": "test_subpackage",
"renderKey": 1652256104063,
"layout": "colFormItem",
"tagIcon": "icon-ym icon-ym-generator-input",
"tag": "el-input",
"regList": [],
"span": 24
},
"readonly": false,
"__vModel__": "contractor",
"style": {
"width": "100%"
},
"disabled": false,
"placeholder": "请输入",
"show-word-limit": false,
"__slot__": {
"prepend": "",
"append": ""
},
"suffix-icon": "",
"on": {
"change": "({ data, formData, setFormData, setShowOrHide, setRequired, setDisabled, request, getFieldOptions, setFieldOptions }) => {\n // 在此编写代码\n \n}",
"blur": "({ data, formData, setFormData, setShowOrHide, setRequired, setDisabled, request, getFieldOptions, setFieldOptions }) => {\n // 在此编写代码\n \n}"
}
}]
对应实体class
@Data
public class FieLdsModel {
private ConfigModel config;
private SlotModel slot;
private String placeholder;
private Object style;
private Boolean clearable;
private String prefixicon;
private Integer precision;
private String suffixicon;
private String maxlength;
private Boolean showWordLimit;
private Boolean readonly;
private Boolean disabled;
private String vModel="";
private String modelId="";
private String relationField;
private Boolean hasPage;
private String pageSize;
private String type;
private Object autosize;
private Integer step;
private Boolean stepstrictly;
private String controlsposition;
private Object textStyle;
private Integer lineHeight;
private Integer fontSize;
private Boolean showChinese;
private Boolean showPassword;
private String size;
private Boolean filterable;
private String showField;
}
@Data
public class ConfigModel {
private String label;
private String labelWidth;
private Boolean showLabel;
private Boolean changeTag;
private Boolean border;
private String tag;
private String tagIcon;
private boolean required = false;
private String layout;
private String dataType;
private Integer span = 24;
private String pfKey;
private String dictionaryType;
private Integer formId;
private Long renderKey;
private Integer columnWidth;
private List<RegListModel> regList;
private Object defaultValue;
private String active;
private String options;
private String valueType;
private String propsUrl;
private String optionType;
private ConfigPropsModel props;
private Boolean showTitle;
private String tableName;
private List<FieLdsModel> children;
private String visibility="[\"app\",\"pc\"]" ;
private String rule;
private String trigger="blur";
private Boolean noShow=false;
private int childNum;
private String model;
private boolean app = true;
private boolean pc = true;
}
@Data
public class SlotModel {
private List<Map<String,Object>> options;
}
@Data
public class RegListModel {
private String pattern;
private String message;
}
@Data
public class ConfigPropsModel {
private String label;
private String value;
}
### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
JSON.parseArray(jsonData, clazz);
希望能转换出 对应属性 的值

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
SlotModel 这个类的代码发一下
能帮忙简化一个重方便重现问题的testcase么?
SlotModel 这个类的代码发一下
可以 删除 那些 不存在得实体类 就留ConfigModel 基本属性 对象属性可以 删除测试
能帮忙简化一个重方便重现问题的testcase么?
JSON.parseArray(jsonData, clazz); 定义好 对应实体类(FieLdsModel ConfigModel ....) 放入上面 jsonData 数据 调用JSON.parseArray(jsonData, clazz) 即可
SlotModel 这个类的代码发一下
对应缺失 类 已补充 麻烦温大佬 看看
JSON.parseArray(jsonData, clazz) , 这里传入的clazz是什么?很抱歉,一直没搞清楚你问题
JSON.parseArray(jsonData, clazz) , 这里传入的clazz是什么?很抱歉,一直没搞清楚你问题
class 是 FieLdsModel 这个类
JSON.parseArray(jsonData, FieLdsModel.class)
FieLdsModel ff = JSON.parseArray(jsonData, FieLdsModel.class)
对应得 config属性 里面 是null
不知我 描述清楚没 这个在1.2.x 是会有值得 但是2.x得 版本 好像不行
目前是不支持识别连续__的名称了,你这个比较奇怪
目前是不支持识别连续__的名称了,你这个比较奇怪
我需要这个得 因为我得项目 就有这个(1.2.x 是会有值得 但是2.x得 版本 好像不行)
可以通过JSONField额外配置
@Data
public static class FieLdsModel {
@JSONField(alternateNames = "__config__")
private ConfigModel config;
支持__会有别别的兼容问题,所以就不支持连续下划线了
可以通过JSONField额外配置
@Data public static class FieLdsModel { @JSONField(alternateNames = "__config__") private ConfigModel config;
支持__会有别别的兼容问题,所以就不支持连续下划线了
好 我试试 谢谢 温大佬 因为1.2.83 我一直没升级 是因为这个版本 是支持__ 2.x 我就没升级上去
可以通过JSONField额外配置
@Data public static class FieLdsModel { @JSONField(alternateNames = "__config__") private ConfigModel config;
支持__会有别别的兼容问题,所以就不支持连续下划线了
好 我试试 谢谢 温大佬 因为1.2.83 我一直没升级 是因为这个版本 是支持__ 2.x 我就没升级上去
这种方式出现其他报错了
@wwkk7080 出现什么其他报错了?
https://github.com/alibaba/fastjson2/releases/tag/2.0.15 问题修复,请用新版本
https://github.com/alibaba/fastjson2/releases/tag/2.0.16 问题已修复,请用2.0.16版本