Skip to content

Commit

Permalink
GH-78 Support enum values with different letter cases and release 1.9…
Browse files Browse the repository at this point in the history
….1 (Resolve #78)
  • Loading branch information
dzikoysk committed Aug 3, 2021
1 parent 425f9f3 commit acbf23b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ repositories {
dependencies {
// Default
implementation 'net.dzikoysk:cdn:1.9.0'
implementation 'net.dzikoysk:cdn:1.9.1'
// Kotlin wrapper
implementation 'net.dzikoysk:cdn-kt:1.9.0'
implementation 'net.dzikoysk:cdn-kt:1.9.1'
}
```

Expand Down
4 changes: 2 additions & 2 deletions cdn-kt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>cdn-parent</artifactId>
<groupId>net.dzikoysk</groupId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -37,7 +37,7 @@
<dependency>
<groupId>net.dzikoysk</groupId>
<artifactId>cdn</artifactId>
<version>1.9.0</version>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
2 changes: 1 addition & 1 deletion cdn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>cdn-parent</artifactId>
<groupId>net.dzikoysk</groupId>
<version>1.9.0</version>
<version>1.9.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
12 changes: 11 additions & 1 deletion cdn/src/main/java/net/dzikoysk/cdn/composers/EnumComposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ public final class EnumComposer implements Composer<Enum<?>>, SimpleDeserializer
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Enum deserialize(AnnotatedType type, String source) {
return Enum.valueOf((Class<Enum>) type.getType(), source);
return searchEnum((Class<Enum>) type.getType(), source);
}

public static <T extends Enum<?>> T searchEnum(Class<T> enumeration, String search) {
for (T each : enumeration.getEnumConstants()) {
if (each.name().equalsIgnoreCase(search)) {
return each;
}
}

throw new IllegalArgumentException("No '" + search + "' enum constant in " + enumeration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EnumComposerTest extends CdnSpec {
@Test
void 'should support enum types' () {
def source = cfg("""
enumValue: VAL
enumValue: val
""")

def result = standard.load(source, ConfigurationWithEnum.class)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>net.dzikoysk</groupId>
<artifactId>cdn-parent</artifactId>
<packaging>pom</packaging>
<version>1.9.0</version>
<version>1.9.1</version>

<scm>
<connection>scm:git:https://github.com/dzikoysk/cdn.git</connection>
Expand Down

0 comments on commit acbf23b

Please sign in to comment.