fastjson2
fastjson2 copied to clipboard
当我entity对象中存在type字段的时候, 反序列化JSONReader.Feature.SupportAutoType. 无法转为我想要的类型
` String str = "[{"type": "STRING11", "@type": "com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO", "displayName": "_id", "logicalName": "_id"}, {"type": "STRING11", "@type": "com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO", "displayName": "_desc", "logicalName": "_desc"}, {"type": "INTEGER", "@type": "com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO", "displayName": "age", "logicalName": "age"}]"; List<RuleOutputFieldDefinitionBO> list3 = (List<RuleOutputFieldDefinitionBO>) JSON.parseObject(str, Object.class,autoTypeFilter,JSONReader.Feature.SupportAutoType,JSONReader.Feature.ErrorOnNotSupportAutoType);
System.out.println(list3.get(0) instanceof RuleOutputFieldDefinitionBO);
System.out.println(list3);
String str1 = "[{\"@type\": \"com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO\", \"displayName\": \"_id\", \"logicalName\": \"_id\"}, { \"@type\": \"com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO\", \"displayName\": \"_desc\", \"logicalName\": \"_desc\"}, {\"type\": \"INTEGER\", \"@type\": \"com.miyo.product.qingkong.logic.engine.abstraction.rule.bo.RuleOutputFieldDefinitionBO\", \"displayName\": \"age\", \"logicalName\": \"age\"}]";
List<RuleOutputFieldDefinitionBO> list4 = (List<RuleOutputFieldDefinitionBO>) JSON.parseObject(str1, Object.class,autoTypeFilter,JSONReader.Feature.SupportAutoType,JSONReader.Feature.ErrorOnNotSupportAutoType);
System.out.println(list4.get(0) instanceof RuleOutputFieldDefinitionBO);
System.out.println(list4.get(0).getClass());
`
简单代码如上. 如果我json中存在了type字段. 就只能反序列化为jsonObject. 而不是我想要的类型了