diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java index 9129c3bad8..cbf1981bf1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedConversionService.java @@ -16,6 +16,9 @@ package org.springframework.boot.bind; +import java.util.EnumSet; +import java.util.Set; + import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; @@ -117,7 +120,14 @@ class RelaxedConversionService implements ConversionService { // It's an empty enum identifier: reset the enum value to null. return null; } - return (T) Enum.valueOf(this.enumType, source.trim().toUpperCase()); + source = source.trim(); + for (T candidate : (Set) EnumSet.allOf(this.enumType)) { + if (candidate.name().equalsIgnoreCase(source)) { + return candidate; + } + } + throw new IllegalArgumentException("No enum constant " + + this.enumType.getCanonicalName() + "." + source); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java index bb9e6b525a..1cb0dd4ddf 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java @@ -442,7 +442,7 @@ public class RelaxedDataBinderTests { result = bind(target, "bingo: oR"); assertThat(result.getErrorCount(), equalTo(0)); - assertThat(target.getBingo(), equalTo(Bingo.OR)); + assertThat(target.getBingo(), equalTo(Bingo.or)); result = bind(target, "bingo: that"); assertThat(result.getErrorCount(), equalTo(0)); @@ -755,7 +755,7 @@ public class RelaxedDataBinderTests { } static enum Bingo { - THIS, OR, THAT + THIS, or, THAT } public static class ValidatedTarget {