Skip to content

Json enum case insensitive #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading