Skip to content

Commit 3727b1c

Browse files
committed
support inputstream
1 parent c4b611e commit 3727b1c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/JsonBUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static Map<String, UType> jsonTypes(ControllerReader reader) {
3333
methodReader -> {
3434
addJsonBodyType(methodReader, addToMap);
3535
if (!methodReader.isVoid()) {
36-
UType uType = UType.parse(methodReader.returnType());
36+
var uType = UType.parse(methodReader.returnType());
3737

38-
if (uType.mainType().equals("java.util.concurrent.CompletableFuture")) {
38+
if ("java.util.concurrent.CompletableFuture".equals(uType.mainType())) {
3939
uType = uType.paramRaw();
4040
}
4141

@@ -51,6 +51,8 @@ private static void addJsonBodyType(MethodReader methodReader, Consumer<UType> a
5151
methodReader.params().stream()
5252
.filter(MethodParam::isBody)
5353
.map(MethodParam::utype)
54+
.filter(s -> !s.full().startsWith("java.io.InputStream"))
55+
.filter(s -> !s.full().startsWith("byte[]"))
5456
.forEach(addToMap);
5557
}
5658
}

http-generator-javalin/src/main/java/io/avaje/http/generator/javalin/JavalinAdapter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ public boolean isBodyMethodParam() {
3131

3232
@Override
3333
public String bodyAsClass(UType type) {
34-
if (useJsonB) {
35-
return type.shortName() + "JsonType.fromJson(ctx.bodyInputStream())";
34+
if (type.full().startsWith("java.io.InputStream")) {
35+
return "ctx.bodyInputStream()";
36+
} else if (type.full().startsWith("byte[]")) {
37+
return "ctx.bodyAsBytes()";
38+
} else {
39+
if (useJsonB) {
40+
return type.shortName() + "JsonType.fromJson(ctx.bodyInputStream())";
41+
}
42+
return "ctx.bodyAsClass(" + type.mainType() + ".class)";
3643
}
37-
return "ctx.bodyAsClass(" + type.mainType() + ".class)";
3844
}
3945

4046
@Override

0 commit comments

Comments
 (0)