File tree Expand file tree Collapse file tree 5 files changed +75
-2
lines changed
http-generator-core/src/main/java/io/avaje/http/generator/core
tests/test-javalin-jsonb/src/main/java/org/example/myapp/web/test Expand file tree Collapse file tree 5 files changed +75
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import static io .avaje .http .generator .core .ParamType .RESPONSE_HANDLER ;
4
4
5
+ import java .util .Optional ;
6
+
5
7
import javax .lang .model .element .Element ;
8
+ import javax .lang .model .element .ElementKind ;
6
9
import javax .lang .model .element .TypeElement ;
7
10
8
11
import io .avaje .http .generator .core .openapi .MethodDocBuilder ;
@@ -42,7 +45,19 @@ public class ElementReader {
42
45
this .rawType = rawType ;
43
46
this .shortType = Util .shortName (rawType );
44
47
this .contextType = ctx .platform ().isContextType (rawType );
45
- this .typeHandler = TypeMap .get (rawType );
48
+
49
+ if (type != null
50
+ && (defaultType == ParamType .FORMPARAM || defaultType == ParamType .QUERYPARAM )
51
+ && Optional .ofNullable (ctx .typeElement (type .mainType ()))
52
+ .map (TypeElement ::getKind )
53
+ .filter (ElementKind .ENUM ::equals )
54
+ .isPresent ()) {
55
+
56
+ this .typeHandler = TypeMap .enumParamHandler (type );
57
+ } else {
58
+
59
+ this .typeHandler = TypeMap .get (rawType );
60
+ }
46
61
this .formMarker = formMarker ;
47
62
this .varName = element .getSimpleName ().toString ();
48
63
this .snakeName = Util .snakeCase (varName );
Original file line number Diff line number Diff line change @@ -43,6 +43,20 @@ static TypeHandler get(String type) {
43
43
return types .get (type );
44
44
}
45
45
46
+ static TypeHandler enumParamHandler (UType type ) {
47
+ return new ObjectHandler (type .mainType (), type .shortName ()) {
48
+ @ Override
49
+ public String toMethod () {
50
+ return type .shortType () + ".valueOf(" ;
51
+ }
52
+
53
+ @ Override
54
+ public String asMethod () {
55
+ return "java.util. Objects.toString(" ;
56
+ }
57
+ };
58
+ }
59
+
46
60
static class StringHandler extends JavaLangType {
47
61
StringHandler () {
48
62
super ("String" );
Original file line number Diff line number Diff line change
1
+ package org .example .myapp .web .test ;
2
+
3
+ public enum ServerType {
4
+ PROXY ,
5
+ HIDE_N_SEEK ,
6
+ FFA
7
+ }
Original file line number Diff line number Diff line change @@ -129,5 +129,4 @@ void neo(
129
129
CompletableFuture <HelloDto > getAllAsync () {
130
130
return CompletableFuture .supplyAsync (() -> new HelloDto (12 , "Jim" , "asd" ));
131
131
}
132
-
133
132
}
Original file line number Diff line number Diff line change
1
+ package org .example .myapp .web .test ;
2
+
3
+ import org .example .myapp .web .HelloDto ;
4
+
5
+ import io .avaje .http .api .Controller ;
6
+ import io .avaje .http .api .Default ;
7
+ import io .avaje .http .api .Form ;
8
+ import io .avaje .http .api .FormParam ;
9
+ import io .avaje .http .api .Get ;
10
+ import io .avaje .http .api .Path ;
11
+ import io .avaje .http .api .Post ;
12
+ import io .avaje .http .api .QueryParam ;
13
+
14
+ @ Path ("test/" )
15
+ @ Controller
16
+ public class TestController2 {
17
+
18
+ @ Form
19
+ @ Get ("/enumForm" )
20
+ String enumForm (String s , ServerType type ) {
21
+ return type .name ();
22
+ }
23
+
24
+ @ Get ("/enumFormParam" )
25
+ String enumFormParam (@ FormParam String s , @ FormParam ServerType type ) {
26
+ return type .name ();
27
+ }
28
+
29
+ @ Get ("/enumQuery" )
30
+ String enumQuery (@ QueryParam @ Default ("FFA" ) ServerType type ) {
31
+ return type .name ();
32
+ }
33
+
34
+ @ Post ("/enumQueryImplied" )
35
+ String enumQueryImplied (HelloDto s , ServerType type ) {
36
+ return type .name ();
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments