json:{aid:"str_id",a_id:12345}
如果ATest.class是这样定义的:class ATest{int a_id;}
JSON.parseObject(json, ATest.class);解析异常
k3fezbri1#
parse 默认开启了FieldSmartMatch, 处理key时会忽略掉下划线,因此在解析时,误把aid当做a_id进行解析,value应该为int但aid对应的value却是str,因此会出现类型转换异常。
FieldSmartMatch
aid
a_id
解决办法:
Feature.DisableFieldSmartMatch
@JSONType(parseFeatures = Feature.DisableFieldSmartMatch) public static class ATest { private int a_id; }
public class ATest { @JSONField(parseFeatures = Feature.DisableFieldSmartMatch) private int a_id; }
1条答案
按热度按时间k3fezbri1#
parse 默认开启了
FieldSmartMatch
, 处理key时会忽略掉下划线,因此在解析时,误把aid
当做a_id
进行解析,value应该为int但aid
对应的value却是str,因此会出现类型转换异常。解决办法:
Feature.DisableFieldSmartMatch
关闭智能匹配即可Feature.DisableFieldSmartMatch
关闭智能匹配即可