Fix the issue that fastjson serializes basic type as string with quotes #256

This commit is contained in:
Francis Dong
2021-07-22 17:56:07 +08:00
committed by dxfeng10
parent 995a93cb69
commit b23b90f2da
2 changed files with 83 additions and 4 deletions

View File

@@ -59,6 +59,7 @@ import we.proxy.FizzWebClient;
import we.proxy.http.HttpInstanceService;
import we.util.JacksonUtils;
import we.util.MapUtil;
import we.util.TypeUtils;
import we.xml.JsonToXml;
import we.xml.XmlToJson;
import we.xml.XmlToJson.Builder;
@@ -363,10 +364,19 @@ public class RequestInput extends RPCInput implements IInput{
if (CONTENT_TYPE_XML.equals(reqContentType) || CONTENT_TYPE_TEXT_XML.equals(reqContentType)) {
// convert JSON to XML if it is XML content type
request.put("jsonBody", request.get("body"));
String jsonStr = JSON.toJSONString(request.get("body"));
String jsonStr = null;
if (TypeUtils.isBasicType(request.get("body"))) {
jsonStr = request.get("body").toString();
} else {
jsonStr = JSON.toJSONString(request.get("body"));
}
LOGGER.info("jsonBody={}", jsonStr);
JsonToXml jsonToXml = new JsonToXml.Builder(jsonStr).build();
body = jsonToXml.toString();
if (jsonStr.startsWith("{") || jsonStr.startsWith("[")) {
JsonToXml jsonToXml = new JsonToXml.Builder(jsonStr).build();
body = jsonToXml.toString();
} else {
body = jsonStr;
}
request.put("body", body);
LOGGER.info("body={}", body);
LOGGER.info("headers={}", JSON.toJSONString(headers));
@@ -379,7 +389,11 @@ public class RequestInput extends RPCInput implements IInput{
} else if (CONTENT_TYPE_FORM_URLENCODED.equals(reqContentType)) {
body = BodyInserters.fromFormData(MapUtil.toMultiValueMap((Map<String, Object>) request.get("body")));
} else {
body = JSON.toJSONString(request.get("body"));
if (TypeUtils.isBasicType(request.get("body"))) {
body = request.get("body").toString();
} else {
body = JSON.toJSONString(request.get("body"));
}
}
HttpMethod aggrMethod = HttpMethod.valueOf(inputContext.getStepContext().getInputReqAttr("method").toString());