Skip to content

Commit

Permalink
json enum case insensitive (#941) (#959)
Browse files Browse the repository at this point in the history
Co-authored-by: Laura Trotta <[email protected]>
  • Loading branch information
github-actions[bot] and l-trotta authored Mar 7, 2025
1 parent 6900670 commit 99ff263
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected Deserializer(T[] values, EnumSet<JsonParser.Event> acceptedEvents) {
for (T member : values) {
String jsonValue = member.jsonValue();
if (jsonValue != null) { // _Custom enum members have a null jsonValue
this.lookupTable.put(jsonValue, member);
this.lookupTable.put(jsonValue.toLowerCase(), member); // lookup must be case-insensitive
}
String[] aliases = member.aliases();
if (aliases != null) {
for (String alias: aliases) {
this.lookupTable.put(alias, member);
this.lookupTable.put(alias.toLowerCase(), member);
}
}
}
Expand All @@ -79,7 +79,7 @@ public T deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event eve
* @throws JsonParsingException if no matching enum was found
*/
public T deserialize(String value, JsonParser parser) {
T result = this.lookupTable.get(value);
T result = this.lookupTable.get(value.toLowerCase());
if (result == null) {
throw new JsonpMappingException("Invalid enum '" + value + "'", parser.getLocation());
}
Expand All @@ -94,7 +94,7 @@ public T deserialize(String value, JsonParser parser) {
* @throws IllegalArgumentException if no matching enum was found
*/
public T parse(String value) {
T result = this.lookupTable.get(value);
T result = this.lookupTable.get(value.toLowerCase());
if (result == null) {
throw new NoSuchElementException("Invalid enum '" + value + "'");
}
Expand Down

0 comments on commit 99ff263

Please sign in to comment.