diff --git a/http-api/src/main/java/io/avaje/http/api/PathTypeConversion.java b/http-api/src/main/java/io/avaje/http/api/PathTypeConversion.java index 1cd272f2..39fc9e1d 100644 --- a/http-api/src/main/java/io/avaje/http/api/PathTypeConversion.java +++ b/http-api/src/main/java/io/avaje/http/api/PathTypeConversion.java @@ -417,6 +417,19 @@ public static LocalDateTime toLocalDateTime(String value) { } } + /** Convert to enum. */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public static Enum toEnum(Class clazz, String value) { + if (isNullOrEmpty(value)) { + return null; + } + try { + return Enum.valueOf((Class) clazz, value.toUpperCase()); + } catch (final IllegalArgumentException e) { + throw new InvalidPathArgumentException(e); + } + } + private static boolean isNullOrEmpty(String value) { return value == null || value.isEmpty(); } diff --git a/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java b/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java index c81938cf..2be4c05b 100644 --- a/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java +++ b/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java @@ -317,7 +317,7 @@ static class EnumHandler extends ObjectHandler { @Override public String toMethod() { - return "(" + type.shortType() + ") asEnum(" + type.shortType() + ".class, "; + return "(" + type.shortType() + ") toEnum(" + type.shortType() + ".class, "; } @Override