How to convert variable to UrlType in Script Mapper

When calling keycloakSession.getContext().getUri(UrlType) I want to pass ‘BACKEND’ as UrlType.
How can I create a variable of type UrlType in the mapper for passing it to the method.
How does the Java.to() method work?
The documentation is for Java but language used is JavaScript. How is it translated?

maybe this way:

UrlType = Java.type("org.keycloak.urls.UrlType");
keycloakSession.getContext().getUri(UrlType.BACKEND);
//alternative
keycloakSession.getContext().getUri(UrlType.valueOf("BACKEND"));

with myJavaType = Java.type("path.to.package.ClassName"); you can import standard Java classes you need. That’s very usefull in scripting.

1 Like

Both ways worked like a charm. Thank you!

Further documentation can be found here: