Skip to content

Commit 1f023ea

Browse files
committed
nima
1 parent 8223d8b commit 1f023ea

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.avaje.http.generator.helidon.nima;
22

33
import static io.avaje.http.generator.core.ProcessingContext.platform;
4+
45
import java.util.List;
56
import java.util.Optional;
67

@@ -53,18 +54,25 @@ void writeHandler(boolean requestScoped) {
5354
} else {
5455
// use default helidon content negotiation
5556
method.params().stream()
56-
.filter(MethodParam::isBody)
57-
.forEach(
58-
param -> {
59-
final var type = param.utype();
60-
writer.append(" var %s = req.content().as(", method.bodyName());
61-
if (type.param0() != null) {
62-
writer.append("new io.helidon.common.GenericType<%s>() {}", type.full());
63-
} else {
64-
writer.append("%s.class", type.full());
65-
}
66-
writer.append(");").eol();
67-
});
57+
.filter(MethodParam::isBody)
58+
.forEach(
59+
param -> {
60+
final var type = param.utype();
61+
62+
writer.append(" var %s = req.content()", method.bodyName());
63+
64+
if (type.full().startsWith("java.io.InputStream")) {
65+
writer.append(".inputStream();").eol();
66+
return;
67+
}
68+
writer.append(".as(");
69+
if (type.param0() != null) {
70+
writer.append("new io.helidon.common.GenericType<%s>() {}", type.full());
71+
} else {
72+
writer.append("%s.class", type.full());
73+
}
74+
writer.append(");").eol();
75+
});
6876
}
6977
} else if (usesFormParams()) {
7078
writer.append(" var formParams = req.content().as(Parameters.class);").eol();
@@ -111,7 +119,7 @@ void writeHandler(boolean requestScoped) {
111119
if (!method.isVoid()) {
112120
writeContextReturn();
113121
if (producesJson()) {
114-
final UType uType = UType.parse(method.returnType());
122+
final var uType = UType.parse(method.returnType());
115123
writer.append(" %sJsonType.toJson(result, res.outputStream());", uType.shortName()).eol();
116124
} else {
117125
writer.append(" res.send(result);").eol();

tests/test-javalin-jsonb/src/main/java/org/example/myapp/web/test/TestController2.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ String mapTest(Map<String, List<String>> strings) {
5050
}
5151

5252
@Get("/inputStream")
53-
String mapTest(InputStream stream) {
53+
String stream(InputStream stream) {
5454
return stream.toString();
5555
}
56+
57+
@Get("/byteArray")
58+
String bytes(byte[] array) {
59+
return array.toString();
60+
}
5661
}

tests/test-nima-jsonb/src/main/java/org/example/TestController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.example;
22

3+
import java.io.InputStream;
34
import java.util.Set;
45

56
import io.avaje.http.api.Controller;
@@ -45,4 +46,9 @@ String enumMultiQuery(@QueryParam @Default({"FFA", "PROXY"}) Set<ServerType> typ
4546
String enumQueryImplied(String s, @QueryParam ServerType type) {
4647
return type.name();
4748
}
49+
50+
@Get("/inputStream")
51+
String stream(InputStream stream) {
52+
return stream.toString();
53+
}
4854
}

0 commit comments

Comments
 (0)