Hamid
Hamid

Reputation: 153

Get the name of the "method argument" in aspect ? (AspectJ)

How can I get the name of argument in aspect, for example if my method is test(Sample sampleDto), I need know the name of sampleDto in my aspect. How get it from ProceedingJoinPoint ? I try this, but I get null.

String[] argumentsName = ((MethodSignature) proceedingJoinPoint.getSignature()).getParameterNames()

Upvotes: 1

Views: 479

Answers (1)

Lenar
Lenar

Reputation: 459

Just tried this and it worked

Reporter.log(gson.toJson(((MethodSignature) jp.getSignature()).getParameterNames()), true);
Reporter.log(gson.toJson(jp.getArgs()), true);

Output

[
  "externalOrderId",
  "tenderDto",
  "checksum",
  "cookieToken"
]
[
  "C605600399",
  {
    "number": "XXXXXXXXXXXXXXXX",
    "expiration": "XXXXXX",
    "pin": "XXX",
    "type": "CREDITCARD"
  },
  1514412484857,
  "50113963101%2CP08rS1wzJiYqQEA3ODEkQVZWLy8sTksmMyNPJH4mXj0jQi1KOThfTld%2BQCQh"
]

Upvotes: 0

Related Questions