Sanitize Keycloak user group names in a Javascript Mapper

Hi,

I had a similar problem using a JavaScript mapper serializing oidc claims (to JSON). I solved it by copying the JavaScript array contents to a plain Java Array and returning this instead of the intermediate JavaScript array. You could try to add this to your code (after the sanitizing, but before returning the groups object):

var resultJArray = java.lang.reflect.Array.newInstance(java.lang.String.class, groups.length);
for (var j = 0; j < groups.length; j++) {
	resultJArray[j] = groups[j];
} 

//one of them might work
token.setOtherClaims("groups", resultJArray);
return groups;

Regards,
Matthias