-
Notifications
You must be signed in to change notification settings - Fork 26.4k
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
Support sending generic requests in JSON format #7637
Conversation
@@ -90,7 +94,9 @@ public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { | |||
generic = RpcContext.getContext().getAttachment(GENERIC_KEY); | |||
} | |||
|
|||
if (StringUtils.isEmpty(generic) | |||
if (ProtocolUtils.isGsonGenericSerialization(generic)) { |
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.
Code clean: This case should after origin first if
judgement.
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.
agree with horizonzy
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.
get
@@ -174,6 +180,14 @@ public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { | |||
return invoker.invoke(inv); | |||
} | |||
|
|||
private Object[] getArgs(final Object[] args, Type[] types) { | |||
Gson gson = new Gson(); |
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.
transfer to instance variable.
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.
get
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.
I think it is better to catch exceptions when converting json to the corresponding type
agree, catch JsonSyntaxException expcetion and throw RpcException. |
@@ -90,7 +94,9 @@ public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { | |||
generic = RpcContext.getContext().getAttachment(GENERIC_KEY); | |||
} | |||
|
|||
if (StringUtils.isEmpty(generic) | |||
if (ProtocolUtils.isGsonGenericSerialization(generic)) { |
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.
agree with horizonzy
private Object[] getArgs(final Object[] args, Type[] types) { | ||
Gson gson = new Gson(); | ||
return IntStream.range(0, args.length).mapToObj(i -> { | ||
String s = args[i].toString(); |
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.
variable s is unnecessary
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.
get
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.
LGTM
Codecov Report
@@ Coverage Diff @@
## master #7637 +/- ##
============================================
- Coverage 59.26% 59.10% -0.17%
Complexity 529 529
============================================
Files 1076 1076
Lines 43529 43542 +13
Branches 6361 6364 +3
============================================
- Hits 25796 25734 -62
- Misses 14879 14935 +56
- Partials 2854 2873 +19 Continue to review full report at Codecov.
|
done |
Please resolve confilcts |
74046cd
to
72ea841
Compare
Invoking a dubbo service via calling from api gateway or running dynamic scripts like groovy by simply passing string values instead of using maps or updating jar files.
像网关和groovy动态脚本这样的调用,可以直接通过传递字符串完成一次rpc调用(不必自己再组装Map之类,或者更新jar包).变的更简单.(golang 夸语言的泛化调用也会大幅度降低难度,毕竟字符串更好产出出来,相较于struct)