Skip to content

Commit e7101f5

Browse files
author
Haydon Perrin
committed
ControllerWriter: Only write JsonType global variables for CompletableFuture's if not already present.
1 parent be06848 commit e7101f5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ private void writeClassStart() {
8989

9090
for (UType type : jsonTypes.values()) {
9191
// Support for CompletableFuture's.
92-
if (type.isGeneric() && type.mainType().equals("java.util.concurrent.CompletableFuture")) {
92+
if (type.mainType().equals("java.util.concurrent.CompletableFuture")) {
9393
type = type.paramRaw();
94+
95+
if (this.jsonTypes.containsKey(type.full())) {
96+
// Already written before -- we can skip.
97+
continue;
98+
}
9499
}
95100

96101
// Everything else
@@ -113,6 +118,12 @@ private void writeClassStart() {
113118
}
114119
if (useJsonB) {
115120
for (final UType type : jsonTypes.values()) {
121+
// Skip trying to assign a global variable value for any UType that is a Completable Future. Because the paramRaw() should
122+
// already be in this jsonTypes map anyway and write the assignment all by itself.
123+
if (type.mainType().equals("java.util.concurrent.CompletableFuture")) {
124+
continue;
125+
}
126+
116127
JsonBUtil.writeJsonbType(type, writer);
117128
}
118129
}

0 commit comments

Comments
 (0)