Reputation: 615
Spring Security here and trying to figure out how to use a MethodInvocation
instance to get:
There is the MethodInvocation#getArguments() : Object[]
method but there is absolutely zero Spring Security documentation as to what type(s) can be returned inside the object array.
Upvotes: 0
Views: 219
Reputation: 90457
It is an array containing all the arguments of the invoked method .The most left argument starts from the index 0 and so on.
Suppose the invoked method is :
void hello(Integer int , String str, Boolean bool);
and it is invoked with :
hello(1000, "world" , true);
Then MethodInvocation#getArguments()
will return an array :
You can use getClass()
on each of the argument object to access their type information and potentially cast it to the actual class if you want to access the specific methods of that type. Something likes:
Object[] args = methodInvocation.getArguments();
args[0].getClass() // return you Integer class
if(args[0] instanceof Integer){
((Integer)arg[0]).intValue(); // cast it to the integer and access a specific method provided by the Integer
}
It returns null if the invoked method does not have any input parameters.
Upvotes: 2