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) {
6464 checkNull (value );
6565 try {
6666 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 ) {
6878 throw new InvalidPathArgumentException (e );
6979 }
7080 }
Original file line number Diff line number Diff line change @@ -310,7 +310,7 @@ static class EnumHandler extends ObjectHandler {
310310
311311 @ Override
312312 public String toMethod () {
313- return type .shortType () + ".valueOf( " ;
313+ return "(" + type .shortType () + ") asEnum(" + type . shortType () + ".class, " ;
314314 }
315315
316316 @ Override
@@ -334,7 +334,7 @@ static class CollectionHandler implements TypeHandler {
334334 (set ? "set" : "list" )
335335 + "("
336336 + (isEnum
337- ? handler .toMethod (). replace ( "." , "::" ). replace ( "(" , "" )
337+ ? "qp -> " + handler .toMethod () + " qp)"
338338 : "PathTypeConversion::" + shortName )
339339 + ", " ;
340340
You can’t perform that action at this time.
0 commit comments