Skip to content

Commit

Permalink
opt code for mvc origin_response config
Browse files Browse the repository at this point in the history
  • Loading branch information
TreasureJade committed Feb 26, 2024
1 parent 5213bee commit f9f0d9a
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions jcommon/docean/src/main/java/com/xiaomi/youpin/docean/Mvc.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,14 @@ public void callMethod(MvcContext context, MvcRequest request, MvcResponse respo
return;
}
// get whether the configuration returns an unwrapped value
if (this.mvcConfig.isResponseOriginalValue()) {
if (data instanceof String) {
response.writeAndFlush(context, (String) data);
} else {
response.writeAndFlush(context, gson.toJson(data));
}
} else if (StringUtils.isNotBlank(this.mvcConfig.getResponseOriginalPath())) {
boolean needOriginalValue = Arrays.stream(mvcConfig.getResponseOriginalPath().split(",")).anyMatch(i -> i.equals(method.getPath()));
if (needOriginalValue) {
if (data instanceof String) {
response.writeAndFlush(context, (String) data);
} else {
response.writeAndFlush(context, gson.toJson(data));
}
} else {
result.setData(data);
response.writeAndFlush(context, gson.toJson(result));
}
boolean needOriginalValue = this.mvcConfig.isResponseOriginalValue();
if (!needOriginalValue && StringUtils.isNotBlank(this.mvcConfig.getResponseOriginalPath())) {
needOriginalValue = Arrays.stream(mvcConfig.getResponseOriginalPath().split(","))
.anyMatch(i -> i.equals(method.getPath()));
}
if (needOriginalValue) {
String responseData = data instanceof String ? (String) data : gson.toJson(data);
response.writeAndFlush(context, responseData);
} else {
result.setData(data);
response.writeAndFlush(context, gson.toJson(result));
Expand Down

0 comments on commit f9f0d9a

Please sign in to comment.