Skip to content

Commit 99ff263

Browse files
json enum case insensitive (#941) (#959)
Co-authored-by: Laura Trotta <153528055+l-trotta@users.noreply.github.com>
1 parent 6900670 commit 99ff263

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: java-client/src/main/java/co/elastic/clients/json/JsonEnums.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ protected Deserializer(T[] values, EnumSet<JsonParser.Event> acceptedEvents) {
5353
for (T member : values) {
5454
String jsonValue = member.jsonValue();
5555
if (jsonValue != null) { // _Custom enum members have a null jsonValue
56-
this.lookupTable.put(jsonValue, member);
56+
this.lookupTable.put(jsonValue.toLowerCase(), member); // lookup must be case-insensitive
5757
}
5858
String[] aliases = member.aliases();
5959
if (aliases != null) {
6060
for (String alias: aliases) {
61-
this.lookupTable.put(alias, member);
61+
this.lookupTable.put(alias.toLowerCase(), member);
6262
}
6363
}
6464
}
@@ -79,7 +79,7 @@ public T deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event eve
7979
* @throws JsonParsingException if no matching enum was found
8080
*/
8181
public T deserialize(String value, JsonParser parser) {
82-
T result = this.lookupTable.get(value);
82+
T result = this.lookupTable.get(value.toLowerCase());
8383
if (result == null) {
8484
throw new JsonpMappingException("Invalid enum '" + value + "'", parser.getLocation());
8585
}
@@ -94,7 +94,7 @@ public T deserialize(String value, JsonParser parser) {
9494
* @throws IllegalArgumentException if no matching enum was found
9595
*/
9696
public T parse(String value) {
97-
T result = this.lookupTable.get(value);
97+
T result = this.lookupTable.get(value.toLowerCase());
9898
if (result == null) {
9999
throw new NoSuchElementException("Invalid enum '" + value + "'");
100100
}

0 commit comments

Comments
 (0)