File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
http-api/src/main/java/io/avaje/http/api
http-generator-core/src/main/java/io/avaje/http/generator/core Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,17 @@ public static int asInt(String value) {
64
64
checkNull (value );
65
65
try {
66
66
return Integer .parseInt (value );
67
- } catch (NumberFormatException e ) {
67
+ } catch (final NumberFormatException e ) {
68
+ throw new InvalidPathArgumentException (e );
69
+ }
70
+ }
71
+
72
+ /** Convert to enum. */
73
+ public static <T > Enum asEnum (Class <T > clazz , String value ) {
74
+ checkNull (value );
75
+ try {
76
+ return Enum .valueOf ((Class <Enum >) clazz , value .toUpperCase ());
77
+ } catch (final IllegalArgumentException e ) {
68
78
throw new InvalidPathArgumentException (e );
69
79
}
70
80
}
Original file line number Diff line number Diff line change @@ -310,7 +310,7 @@ static class EnumHandler extends ObjectHandler {
310
310
311
311
@ Override
312
312
public String toMethod () {
313
- return type .shortType () + ".valueOf( " ;
313
+ return "(" + type .shortType () + ") asEnum(" + type . shortType () + ".class, " ;
314
314
}
315
315
316
316
@ Override
@@ -334,7 +334,7 @@ static class CollectionHandler implements TypeHandler {
334
334
(set ? "set" : "list" )
335
335
+ "("
336
336
+ (isEnum
337
- ? handler .toMethod (). replace ( "." , "::" ). replace ( "(" , "" )
337
+ ? "qp -> " + handler .toMethod () + " qp)"
338
338
: "PathTypeConversion::" + shortName )
339
339
+ ", " ;
340
340
You can’t perform that action at this time.
0 commit comments