Finally, I managed to get it to work using the following:
/v1/Users?%24filter=(id eq $getobject.nativeIdentity$)&%24select=userLogin,id&%24expand=roleStaticUsers(%24select=rolesId)
Only the “$” that are not part of the variable should be encoded
The “$” symbols that are part of placeholders must remain unencoded
I think there was a mistake in the first tests I did.
Thank you all for your suggestions!