I'm trying to get a specific attribute of an Object. In my code, I have an object "asdf2" with the follow attributes:
I need to get the "keyElement" attribute of my "asdf2".
My code with the attempts:
public Object logRedisOperations(ProceedingJoinPoint joinPoint) throws Throwable { Object asdf2 = joinPoint.getArgs()[0]; // see the debug image above to understand the "asdf2" Object // Attempt 1: Using cast RedisCache args1 = (RedisCache) asdf2; // Failed. Throw an exception: java.lang.ClassCastException: org.springframework.data.redis.cache.RedisCache$2 cannot be cast to org.springframework.data.redis.cache.RedisCache ... // Attempt 2: Using cast RedisCache$2 args2 = (RedisCache$2) asdf2; // Class "RedisCache$2" not found // Attempt 3: Using reflection Field[] fields = asdf2.getClass().getDeclaredFields(); // Get only the 'this$0' field.setAccessible(true); // Attempt 4: Convert to json String jsonTest = new Gson().toJson(asdf2); // Return {} // Target!! String keyElement = "I need of 'asdf2.element.cacheKey.keyElement' value here" // ...}
Would anyone know how can I get the "keyElement" attribute of the "asdf2" object?