Skip to content

Commit

Permalink
make enum parser case-insensitve fix #409
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Jul 1, 2016
1 parent 4a69db8 commit 4aec37c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions coverage-report/src/test/java/org/jooby/issues/Issue409.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jooby.issues;

import org.jooby.test.ServerFeature;
import org.junit.Test;

public class Issue409 extends ServerFeature {

public enum Letter {A, B, C}

{
get("/409/:letter", req -> req.param("letter").toEnum(Letter.class));
}

@Test
public void caseInsensitveEnumParser() throws Exception {
request()
.get("/409/a")
.expect("A");

request()
.get("/409/A")
.expect("A");
}

}
4 changes: 2 additions & 2 deletions jooby/src/main/java/org/jooby/internal/BuiltinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public Object parse(final TypeLiteral<?> type, final Parser.Context ctx)
if (Enum.class.isAssignableFrom(rawType)) {
return ctx
.param(values ->
java.lang.Enum.valueOf(rawType, values.get(0))
java.lang.Enum.valueOf(rawType, values.get(0).toUpperCase())
).body(body ->
java.lang.Enum.valueOf(rawType, body.text())
java.lang.Enum.valueOf(rawType, body.text().toUpperCase())
);
} else {
return ctx.next();
Expand Down

0 comments on commit 4aec37c

Please sign in to comment.