Skip to content

Commit 50cc404

Browse files
committed
Nima - When returning JSON as String assume the string is raw json
1 parent 9f7baea commit 50cc404

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

http-generator-nima/src/main/java/io/avaje/http/generator/helidon/nima/ControllerMethodWriter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ void writeHandler(boolean requestScoped) {
113113
final var uType = UType.parse(method.returnType());
114114
writer.append(" result.transferTo(res.outputStream());", uType.shortName()).eol();
115115
} else if (producesJson()) {
116-
final var uType = UType.parse(method.returnType());
117-
writer.append(" %sJsonType.toJson(result, JsonOutput.of(res));", uType.shortName()).eol();
116+
if (returnTypeString()) {
117+
writer.append(" res.send(result); // send raw JSON").eol();
118+
} else {
119+
final var uType = UType.parse(method.returnType());
120+
writer.append(" %sJsonType.toJson(result, JsonOutput.of(res));", uType.shortName()).eol();
121+
}
118122
} else {
119123
writer.append(" res.send(result);").eol();
120124
}
@@ -159,6 +163,10 @@ private boolean producesJson() {
159163
&& (method.produces() == null || method.produces().toLowerCase().contains("json"));
160164
}
161165

166+
private boolean returnTypeString() {
167+
return "java.lang.String".equals(method.returnType().toString());
168+
}
169+
162170
private boolean missingServerResponse(List<MethodParam> params) {
163171
return method.isVoid() && params.stream().noneMatch(p -> "ServerResponse".equals(p.shortType()));
164172
}

0 commit comments

Comments
 (0)