Open alw8829 opened 3 years ago
JSON.parseObject 时,如果 TypeReference<Map<String, String>> ,那么当jsonStr包含引用时,会报错或者丢属性(引用属性是数组项时)。 测试了几个版本,1.2.56 会报错 UnsupportedOperationException 1.2.31 1.2.71 会丢引用的属性
原因(1.2.56) com.alibaba.fastjson.parser.DefaultJSONParser#handleResovleTask 的时候 value已经是Map<String,String> 了, 所以com.alibaba.fastjson.JSONPath#getArrayItem 里 currentObject 是String 原因(1.2.71 ) com.alibaba.fastjson.JSONPath#getPropertyValue currentObject 是String 时,JSONObject object = JSON.parseObject((String)currentObject) 报错 并被catch,最后return了null
测试代码:(1.2.56 报错UnsupportedOperationException ,1.2.71 丢失 type属性 )
public static void main(String[] args) { String s = "{\"com.taobao.ju.my.bbf.config.BbfConfigHolder.activities\":[{\"calType\":2," + "\"type\":{\"name\":\"ITEM_TAG\"}},{\"calType\":2,\"type\":{\"$ref\":\"$.com\\\\.taobao\\\\.ju\\\\" + ".my\\\\.bbf\\\\.config\\\\.BbfConfigHolder\\\\.activities[0].type\"}}]}"; Map<String, String> mockMapObj = JSON.parseObject(s,new TypeReference<Map<String, String>>(){}); System.out.println(mockMapObj); }
请问有人正在处理这个问题吗?我对这个issue挺感兴趣的,我想在最近的几个月内尝试处理这个bug
实测,最新版本无问题了 @alw8829
JSON.parseObject 时,如果 TypeReference<Map<String, String>> ,那么当jsonStr包含引用时,会报错或者丢属性(引用属性是数组项时)。 测试了几个版本,1.2.56 会报错 UnsupportedOperationException 1.2.31 1.2.71 会丢引用的属性
原因(1.2.56) com.alibaba.fastjson.parser.DefaultJSONParser#handleResovleTask 的时候 value已经是Map<String,String> 了, 所以com.alibaba.fastjson.JSONPath#getArrayItem 里 currentObject 是String 原因(1.2.71 ) com.alibaba.fastjson.JSONPath#getPropertyValue currentObject 是String 时,JSONObject object = JSON.parseObject((String)currentObject) 报错 并被catch,最后return了null
测试代码:(1.2.56 报错UnsupportedOperationException ,1.2.71 丢失 type属性 )