网上一堆答案,官网给出的enable_autotype · alibaba/fastjson Wiki · GitHub
我的问题其实很简单:
{
....
ErrorMsgObject errorMsgObject = new ErrorMsgObject(msg, req, e);
errorMsgObject.setStatus("failed");
log.error(JSONObject.toJSONString(logErrorMsgObejct));
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(errorMsgObject), JSONObject.class);
return jsonObject;
}
注意我的errorMsgObject里面有个字段含有“@type”,因此在反序列化的时候出现了报错:autoType is not support
一行代码解决:
JSONObject.parseObject(JSONObject.toJSONString(errorMsgObject), JSONObject.class, Feature.DisableSpecialKeyDetect);
开启autotype
Feature.DisableSpecialKeyDetect