Skip to content

Commit 0aaa1c8

Browse files
authored
Add compiler error for GET json bodies (#581)
* Add compiler error for GET bodies
1 parent a61aa58 commit 0aaa1c8

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class MethodReader {
6060
this.bean = bean;
6161
this.element = element;
6262
this.actualExecutable = actualExecutable;
63-
this.actualParams = (actualExecutable == null) ? null : actualExecutable.getParameterTypes();
63+
this.actualParams = actualExecutable == null ? null : actualExecutable.getParameterTypes();
6464
this.isVoid = element.getReturnType().getKind() == TypeKind.VOID;
6565
this.methodRoles = Util.findRoles(element);
6666
this.producesAnnotation =
@@ -327,7 +327,7 @@ void read() {
327327
}
328328
// non-path parameters default to form or query parameters based on the
329329
// existence of @Form annotation on the method
330-
final ParamType defaultParamType = (formMarker) ? ParamType.FORMPARAM : ParamType.QUERYPARAM;
330+
final ParamType defaultParamType = formMarker ? ParamType.FORMPARAM : ParamType.QUERYPARAM;
331331

332332
final List<? extends VariableElement> parameters = element.getParameters();
333333
for (int i = 0; i < parameters.size(); i++) {
@@ -342,6 +342,15 @@ void read() {
342342
final UType type = Util.parse(typeMirror.toString());
343343
final MethodParam param = new MethodParam(p, type, rawType, defaultParamType, formMarker);
344344
params.add(param);
345+
346+
if (CoreWebMethod.GET.equals(webMethod)
347+
&& param.isBody()
348+
&& !"java.util.Map".equals(param.utype().mainType())
349+
&& !"ClientPlatformAdapter"
350+
.equals(ProcessingContext.platform().getClass().getSimpleName())) {
351+
logError(p, "Missing @BeanParam annotation");
352+
}
353+
345354
param.addImports(bean);
346355
}
347356
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ String mapTest(Map<String, List<String>> strings) {
4949
return strings.toString();
5050
}
5151

52-
@Get("/inputStream")
52+
@Post("/inputStream")
5353
@Consumes("application/bson")
5454
String stream(InputStream stream) {
5555
return stream.toString();
5656
}
5757

58-
@Get("/byteArray")
58+
@Post("/byteArray")
5959
String bytes(byte[] array) {
6060
return array.toString();
6161
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ String enumQueryImplied(String s, @QueryParam ServerType type) {
8181
}
8282

8383
@InstrumentServerContext
84-
@Get(value = "/inputStream")
84+
@Post(value = "/inputStream")
8585
InputStream stream(InputStream stream) throws Exception {
8686
return stream;
8787
}

0 commit comments

Comments
 (0)