-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# mock文件路径 | ||
foxMockFilePath=/Users/yinjihuan/Downloads/foxmockdata | ||
foxMockFilePath=/Users/yinjihuan/Documents/foxmockdata | ||
# foxmock的agent jar包路径,不填默认为当前文件夹 | ||
foxMockAgentJarPath=fox-mock-agent/target/fox-mock-agent-2.0-SNAPSHOT.jar | ||
foxMockAgentJarPath=fox-mock-agent/target/fox-mock-agent-3.0.jar | ||
# mock方法白名单,如果文件夹中有多个方法会被全部mock,如果指定了此配置将只会mock这里指定的方法 | ||
mockMethodWhiteList=com.cxytiandi.foxmock.example.UserService#getAge|com.cxytiandi.foxmock.example.UserService#getAddrs | ||
#mockMethodWhiteList=com.cxytiandi.foxmock.example.UserService#getAge|com.cxytiandi.foxmock.example.UserService#getName2 | ||
# httpn mock数据地址,可以对接配置中心,必须是get请求 | ||
#mockDataHttpUrl=http%3A%2F%2F47.105.66.210%3A8848%2Fnacos%2Fv1%2Fcs%2Fconfigs%3FdataId%3Dfox-mock%26group%3DDEFAULT_GROUP%26tenant%3D9c9f5197-688c-4ef9-ae68-1ff28663301d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
fox-mock-agent/src/main/java/com/cxytiandi/foxmock/agent/utils/JsonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.cxytiandi.foxmock.agent.utils; | ||
|
||
import com.google.gson.Gson; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* JSON转换工具类,由于javassist不支持泛型,所以采用了一个折中的方式,在这里处理好带泛型的对象 | ||
* | ||
* @作者 尹吉欢 | ||
* @个人微信 jihuan900 | ||
* @微信公众号 猿天地 | ||
* @GitHub https://github.com/yinjihuan | ||
* @作者介绍 http://cxytiandi.com/about | ||
* @时间 2022-05-06 21:20 | ||
*/ | ||
public class JsonUtils { | ||
|
||
public static Object parse(String data, String className, String methodName) { | ||
try { | ||
Type genericReturnType = null; | ||
Class<?> clazz = Class.forName(className.replace('/','.')); | ||
Method[] declaredMethods = clazz.getDeclaredMethods(); | ||
for (Method m: declaredMethods) { | ||
if (m.getName().equals(methodName)){ | ||
genericReturnType = m.getGenericReturnType(); | ||
break; | ||
} | ||
} | ||
|
||
Gson gson = new Gson(); | ||
Object value = gson.fromJson(data, genericReturnType); | ||
return value; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters