Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

(Java) Get attribute of an Object ($...)

$
0
0

I'm trying to get a specific attribute of an Object. In my code, I have an object "asdf2" with the follow attributes:

enter image description here

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?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>