roleValueFromJson function
Converts a JSON role string to a corresponding RoleValue enumeration.
This function takes a JSON role string as input and converts it to the
corresponding RoleValue
enumeration. If the input string is null, empty,
or matches the constant UNKNOWN
, the function returns the default role
RoleValue.CONTENT_MANAGEMENT
. Otherwise, it compares the lowercase names
of the RoleValue
enum values with the lowercase input string to find a match.
The first matching RoleValue
enum is returned. If no match is found, an
exception will be thrown.
@param roleString The JSON role string to convert to a RoleValue
enum.
@return A RoleValue
enum corresponding to the input role string.
Implementation
RoleValue roleValueFromJson(String? roleString) {
if (roleString == null || roleString.isEmpty || roleString == UNKNOWN) {
return RoleValue.CONTENT_MANAGEMENT;
}
return RoleValue.values.firstWhere((RoleValue role) {
return role.name.toLowerCase().compareTo(roleString.toLowerCase()) == 0;
});
}