Skip to content

Commit be06848

Browse files
author
Haydon Perrin
committed
Moved CompletableFuture generic validation to ControllerMethodWriter.
1 parent b4b124c commit be06848

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ private static void addJsonBodyType(MethodReader methodReader, Consumer<UType> a
5252
public static void writeJsonbType(UType type, Append writer) {
5353
// Support for CompletableFuture's.
5454
if (type.mainType().equals("java.util.concurrent.CompletableFuture")) {
55-
if (!type.isGeneric()) {
56-
throw new IllegalStateException("CompletableFuture usages must have a generic type defined. e.g. `CompletableFuture<String>` or `CompletableFuture<Void>`.");
57-
}
58-
5955
writeJsonbType(type.paramRaw(), writer);
6056
return;
6157
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ void write(boolean requestScoped) {
8787
private void writeContextReturn() {
8888
// Support for CompletableFuture's.
8989
final UType type = UType.parse(method.returnType());
90-
if (type.isGeneric() && type.mainType().equals("java.util.concurrent.CompletableFuture")) {
90+
if (type.mainType().equals("java.util.concurrent.CompletableFuture")) {
91+
if (!type.isGeneric()) {
92+
throw new IllegalStateException("CompletableFuture must be generic type (e.g. CompletableFuture<String>, CompletableFuture<Void>).");
93+
}
94+
9195
final String futureResultVariableName = "futureResult";
9296

9397
writer.append(" ctx.future(() -> {").eol();
@@ -108,7 +112,7 @@ private void writeContextReturn(final String resultVariableName) {
108112
if (produces == null || MediaType.APPLICATION_JSON.equalsIgnoreCase(produces)) {
109113
if (useJsonB) {
110114
var uType = UType.parse(method.returnType());
111-
if (uType.isGeneric() && uType.mainType().equals("java.util.concurrent.CompletableFuture")) {
115+
if (uType.mainType().equals("java.util.concurrent.CompletableFuture")) {
112116
uType = uType.paramRaw();
113117
}
114118

0 commit comments

Comments
 (0)