fix(fastjson): 转JsonObject过滤key

--user=郭雨琦
转JsonObject过滤key
This commit is contained in:
guoyuqi 2022-04-15 11:58:07 +08:00 committed by TIanyang
parent 65299e287a
commit cc7508dd61
9 changed files with 21 additions and 15 deletions

View File

@ -649,7 +649,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
// schema.put("example", param.getString("value"));
// swaggerParam.setSchema(schema);
// }
paramsList.add(JSON.parseObject(JSON.toJSONString(swaggerParam)));
paramsList.add(JSON.parseObject(JSON.toJSONString(swaggerParam),Feature.DisableSpecialKeyDetect));
}
}
}

View File

@ -203,7 +203,7 @@ public class TestResult {
}
if (StringUtils.isNotEmpty(item.getScenario())) {
List<String> id_names = JSON.parseObject(item.getScenario(), List.class);
List<String> id_names = JSON.parseObject(item.getScenario(), List.class, Feature.DisableSpecialKeyDetect);
this.setStatus(id_names, item.getError() > 0);
return item.getScenario();
} else {

View File

@ -1378,7 +1378,7 @@ public class ApiAutomationService {
if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) {
return;
}
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(),Feature.DisableSpecialKeyDetect);
JSONArray hashTree = element.getJSONArray("hashTree");
ApiScenarioImportUtil.formatHashTree(hashTree);
setHashTree(hashTree);
@ -1402,7 +1402,7 @@ public class ApiAutomationService {
if (CollectionUtils.isEmpty(object.getJSONArray("hashTree"))) {
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id"));
if (model != null) {
JSONObject element = JSON.parseObject(model.getRequest());
JSONObject element = JSON.parseObject(model.getRequest(),Feature.DisableSpecialKeyDetect);
object.put("hashTree", element.getJSONArray("hashTree"));
}
}

View File

@ -2,6 +2,7 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.APIReportResult;
@ -1973,7 +1974,7 @@ public class ApiDefinitionService {
ApiDefinitionWithBLOBs bloBs = apiDefinitionMapper.selectByPrimaryKey(id);
List<DocumentElement> elements = new LinkedList<>();
if (bloBs != null && StringUtils.isNotEmpty(bloBs.getResponse())) {
JSONObject object = JSON.parseObject(bloBs.getResponse());
JSONObject object = JSON.parseObject(bloBs.getResponse(), Feature.DisableSpecialKeyDetect);
JSONObject body = (JSONObject) object.get("body");
if (body != null) {
String raw = body.getString("raw");

View File

@ -3,6 +3,7 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.*;
import io.metersphere.api.dto.automation.APIScenarioReportResult;
import io.metersphere.api.dto.automation.ExecuteType;
@ -452,7 +453,7 @@ public class ApiScenarioReportService {
String environmentType = apiScenario.getEnvironmentType();
if (StringUtils.equals(environmentType, EnvironmentType.JSON.name()) && StringUtils.isNotEmpty(apiScenario.getEnvironmentJson())) {
String environmentJson = apiScenario.getEnvironmentJson();
JSONObject jsonObject = JSON.parseObject(environmentJson);
JSONObject jsonObject = JSON.parseObject(environmentJson, Feature.DisableSpecialKeyDetect);
ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
List<String> collect = jsonObject.values().stream().map(Object::toString).collect(Collectors.toList());
collect.add("-1");// 防止没有配置环境导致不能发送的问题

View File

@ -3,6 +3,7 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO;
import io.metersphere.api.dto.ApiScenarioReportDTO;
import io.metersphere.api.dto.RequestResultExpandDTO;
@ -122,7 +123,7 @@ public class ApiScenarioReportStructureService {
}
public static StepTreeDTO dataFormatting(String id, String name, String scenarioDefinition, String reportType) {
JSONObject element = JSON.parseObject(scenarioDefinition);
JSONObject element = JSON.parseObject(scenarioDefinition, Feature.DisableSpecialKeyDetect);
StepTreeDTO dto = null;
if (element != null && element.getBoolean("enable")) {
element = getRefElement(element);
@ -150,7 +151,7 @@ public class ApiScenarioReportStructureService {
if (StringUtils.equals(element.getString("type"), "scenario")) {
ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id"));
if (scenarioWithBLOBs != null) {
return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(), Feature.DisableSpecialKeyDetect);
}
}
}

View File

@ -2,6 +2,7 @@ package io.metersphere.job.sechedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.ApiTestImportRequest;
import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
import io.metersphere.api.dto.scenario.KeyValue;
@ -55,7 +56,7 @@ public class SwaggerUrlImportJob extends MsScheduleJob {
public void setAuthInfo(String config, ApiTestImportRequest request){
// 获取鉴权设置
if(StringUtils.isNotBlank(config)){
JSONObject configObj = JSON.parseObject(config);
JSONObject configObj = JSON.parseObject(config, Feature.DisableSpecialKeyDetect);
List<KeyValue> headers = JSONObject.parseArray(configObj.getString("headers"), KeyValue.class);
if(CollectionUtils.isNotEmpty(headers)){
request.setHeaders(headers);

View File

@ -2,6 +2,7 @@ package io.metersphere.log.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.api.dto.definition.request.sampler.MsDubboSampler;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
@ -26,8 +27,8 @@ public class ApiDefinitionDiffUtil {
public static String diffResponse(String newValue, String oldValue) {
Map<String, String> diffMap = new LinkedHashMap<>();
JSONObject bloBsNew = JSON.parseObject(newValue);
JSONObject bloBsOld = JSON.parseObject(oldValue);
JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect);
JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect);
if (bloBsNew == null || StringUtils.isEmpty(bloBsNew.getString("type"))) {
return null;
}
@ -43,8 +44,8 @@ public class ApiDefinitionDiffUtil {
public static String diff(String newValue, String oldValue) {
try {
JSONObject bloBsNew = JSON.parseObject(newValue);
JSONObject bloBsOld = JSON.parseObject(oldValue);
JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect);
JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect);
if (bloBsNew == null || StringUtils.isEmpty(bloBsNew.getString("type"))) {
return null;
}

View File

@ -2,6 +2,7 @@ package io.metersphere.log.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.metersphere.commons.utils.LogUtil;
import org.apache.commons.lang3.StringUtils;
import java.util.LinkedHashMap;
@ -11,8 +12,8 @@ public class ApiTestEnvironmentDiffUtil {
public static String diff(String newValue, String oldValue) {
try {
JSONObject bloBsNew = JSON.parseObject(newValue);
JSONObject bloBsOld = JSON.parseObject(oldValue);
JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect);
JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect);
Map<String, String> diffMap = new LinkedHashMap<>();
diffMap.put("type", "preAndPostScript");