-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修改请求参数转换逻辑 #1347
修改请求参数转换逻辑 #1347
Conversation
Hi @miaomiaoLmm, welcome to SOFAStack community, Please sign Contributor License Agreement! After you signed CLA, we will automatically sync the status of this pull request in 3 minutes. |
Hi @miaomiaoLmm, welcome to SOFAStack community, Please sign Contributor License Agreement! After you signed CLA, we will automatically sync the status of this pull request in 3 minutes. |
Codecov Report
@@ Coverage Diff @@
## master #1347 +/- ##
============================================
- Coverage 72.05% 72.05% -0.01%
- Complexity 783 784 +1
============================================
Files 416 416
Lines 17661 17668 +7
Branches 2752 2753 +1
============================================
+ Hits 12726 12730 +4
Misses 3533 3533
- Partials 1402 1405 +3
|
if (jsonMethod == null) { | ||
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_METHOD_NOT_FOUND, clazz.getName(), | ||
methodName)); | ||
} | ||
|
||
// parse request types | ||
Type[] parameterTypes = jsonMethod.getGenericParameterTypes(); | ||
Type[] parameterTypes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miaomiaoLmm Please add a single test to ensure problem resolution.
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use * in import statements. You can set it in IDE configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New pull request I removed util.*
pls do a 'mvn clean package -Dmaven.test.skip=true' before u commit and push |
if (jsonMethod.getDeclaringClass() != clazz && !clazz.isInterface()) { | ||
parameterTypes = new Type[1]; | ||
Type type = clazz.getGenericSuperclass(); | ||
ParameterizedType parameterizedType = (ParameterizedType) type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if clazz.getGenericSuperclass() returns type which is not ParameterizedType?
Say if Class c extends B implement A
, B may not always be a ParameterizedType.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new pull request fixes the parent object non-ParameterizedType conversion problem
… father object/super object definition apply method, and definition requestType and responseType, type change fixed success 2. The TestRequest2 method is provided to test the problem of parent class non-ParameterizedType conversion
… father object/super object definition apply method, and definition requestType and responseType, type change fixed success 2. The TestRequest2 method is provided to test the problem of parent class non-ParameterizedType conversion
… father object/super object definition apply method, and definition requestType and responseType, type change fixed success 2. The TestRequest2 method is provided to test the problem of parent class non-ParameterizedType conversion
try { | ||
ParameterizedType parameterizedType = (ParameterizedType) type; | ||
// parse request types | ||
parameterTypes[0] = parameterizedType.getActualTypeArguments()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里感觉还是有问题的,应该无法保证所有走到这里的case都是 Class A<X, Y> 的形式? Class A<X, Y, Z> 或者 Class A<X> 应该都会触发异常
if (jsonMethod.getDeclaringClass() != clazz && !clazz.isInterface()) { | ||
parameterTypes = new Type[1]; | ||
Type type = clazz.getGenericSuperclass(); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以用if else来处理,尽量不要使用 try catch 当 ifelse 用
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
修改请求参数转换逻辑:
问题:rpc请求序列化异常,rpc请求进行request参数序列化,由于子类没有重写apply方法,导致从父类获取apply方法中的request和response类型,由于类型定义为范型,request参数序列化过程会自动转换为linkedHashMap类型并请求apply方法,由于apply方法中调用的process方法确定了实际的request类型,导致linkedHashMap转换Request类型异常
解决方案:判断重写apply方法的class类是否为目标类,如果不是目标类,通过获取目标类上确定的Request和Response类型进行请求参数序列化。