|
@@ -37,42 +37,6 @@ public class ApiJsonPayloadResolver implements ApiPayloadResolver {
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 遍历json
|
|
|
- * @param jsonElement json元素
|
|
|
- * @param context 上下文
|
|
|
- * @param deep 深度
|
|
|
- */
|
|
|
- public void traverseJson(JsonElement jsonElement, JsonElement currentElement,String currentKey,ApiResult context,Integer deep) {
|
|
|
- deep++;
|
|
|
- if(deep >= MAX_DEEP){
|
|
|
- throw new BizException(String.format("请求payload的json配置深度达到允许的最大深度[%s]!",MAX_DEEP));
|
|
|
- }
|
|
|
- if (jsonElement.isJsonObject()) {
|
|
|
- JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
- for (String key : jsonObject.keySet()) {
|
|
|
- traverseJson(jsonObject.get(key),jsonObject,key,context,deep);
|
|
|
- }
|
|
|
- } else if (jsonElement.isJsonArray()) {
|
|
|
- JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
|
- for (JsonElement elem : jsonArray) {
|
|
|
- traverseJson(elem,currentElement,null,context,deep);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()){
|
|
|
- String value = jsonElement.getAsString();
|
|
|
- if(value.startsWith(CONFIG_PREFIX_SIGN)&&value.endsWith(CONFIG_END_SIGN)){
|
|
|
- JsonPrimitive newElement = parseSpelConfigToRealValue(jsonElement,context);
|
|
|
- if(StringUtils.isNotBlank(currentKey)){
|
|
|
- currentElement.getAsJsonObject().add(currentKey,newElement);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 遍历json
|
|
|
* @param jsonElement json元素
|
|
@@ -107,26 +71,6 @@ public class ApiJsonPayloadResolver implements ApiPayloadResolver {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 将spel表达式转换成真实值
|
|
|
- * @param jsonElement json元素
|
|
|
- */
|
|
|
- private JsonPrimitive parseSpelConfigToRealValue(JsonElement jsonElement, ApiResult context){
|
|
|
- String value = jsonElement.getAsString();
|
|
|
- value = StringUtils.replace(value,CONFIG_PREFIX_SIGN,"{",3);
|
|
|
- ValueObject valueObject = new Gson().fromJson(value,ValueObject.class);
|
|
|
- Object realValue = valueObject.compile(context).getRealValue();
|
|
|
- if(realValue instanceof Number){
|
|
|
- return new JsonPrimitive((Number)realValue);
|
|
|
- }else if(realValue instanceof String){
|
|
|
- return new JsonPrimitive((String)realValue);
|
|
|
- }else if(realValue instanceof Boolean){
|
|
|
- return new JsonPrimitive((Boolean)realValue);
|
|
|
- }else if(realValue instanceof Character){
|
|
|
- return new JsonPrimitive((Character)realValue);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 将spel表达式转换成真实值
|