mercredi 29 juin 2016

JAVA Reflection - JoinPoint

I'm trying to use java reflection to get details about some execution and save it in gray log.

Gray log methods accept join point parameters, but i can't get much information, i'd like to get all information a cast it to JSON, can you help how to do this ?

This is what i've tried:

MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Object[] args = joinPoint.getArgs();
for (Object a : args) {
            if (a.getClass().toString().toLowerCase().contains("request")) {
                Method[] methods = a.getClass().getMethods();
                for (Method m : methods){
                    if (m.getName().substring(0, 3).toLowerCase().equals("get")) {
                        Object result = m.invoke(a);
                        jArray = new JSONArray();
                        jObject = new JSONObject();
                        if (result instanceof List<?>) {
... } } } } }

this implies that i have to test all instanceof that same result, what i want is to get the info and parse it to JSON.





Aucun commentaire:

Enregistrer un commentaire