Skip to content

Add compiler error for GET json bodies #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class MethodReader {
this.bean = bean;
this.element = element;
this.actualExecutable = actualExecutable;
this.actualParams = (actualExecutable == null) ? null : actualExecutable.getParameterTypes();
this.actualParams = actualExecutable == null ? null : actualExecutable.getParameterTypes();
this.isVoid = element.getReturnType().getKind() == TypeKind.VOID;
this.methodRoles = Util.findRoles(element);
this.producesAnnotation =
Expand Down Expand Up @@ -327,7 +327,7 @@ void read() {
}
// non-path parameters default to form or query parameters based on the
// existence of @Form annotation on the method
final ParamType defaultParamType = (formMarker) ? ParamType.FORMPARAM : ParamType.QUERYPARAM;
final ParamType defaultParamType = formMarker ? ParamType.FORMPARAM : ParamType.QUERYPARAM;

final List<? extends VariableElement> parameters = element.getParameters();
for (int i = 0; i < parameters.size(); i++) {
Expand All @@ -342,6 +342,15 @@ void read() {
final UType type = Util.parse(typeMirror.toString());
final MethodParam param = new MethodParam(p, type, rawType, defaultParamType, formMarker);
params.add(param);

if (CoreWebMethod.GET.equals(webMethod)
&& param.isBody()
&& !"java.util.Map".equals(param.utype().mainType())
&& !"ClientPlatformAdapter"
.equals(ProcessingContext.platform().getClass().getSimpleName())) {
logError(p, "Missing @BeanParam annotation");
}

param.addImports(bean);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ String mapTest(Map<String, List<String>> strings) {
return strings.toString();
}

@Get("/inputStream")
@Post("/inputStream")
@Consumes("application/bson")
String stream(InputStream stream) {
return stream.toString();
}

@Get("/byteArray")
@Post("/byteArray")
String bytes(byte[] array) {
return array.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ String enumQueryImplied(String s, @QueryParam ServerType type) {
}

@InstrumentServerContext
@Get(value = "/inputStream")
@Post(value = "/inputStream")
InputStream stream(InputStream stream) throws Exception {
return stream;
}
Expand Down