mardi 25 décembre 2018

Getting invalid class name using reflection in java

I am using java reflection in my code and iterating inside a class. On iteration I am getting an invalid class name for a particular object. PFB the code of reflection and the the logs i am getting.

LOGGERS :

2018-12-26 12:38:04,878 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- given class is : class com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- fields are : private javassist.util.proxy.MethodHandler com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e.handler
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- fields are : public static byte[] com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e._filter_signature
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- fields are : public static final long com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e.serialVersionUID
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- fields are : private static java.lang.reflect.Method[] com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e._methods_
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- field is : handler path is : relatedBusinessSolutionMapping
2018-12-26 12:38:04,879 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- field is : _filter_signature path is : relatedBusinessSolutionMapping
2018-12-26 12:38:04,880 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- field is : serialVersionUID path is : relatedBusinessSolutionMapping
2018-12-26 12:38:04,880 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- field is : _methods_ path is : relatedBusinessSolutionMapping
2018-12-26 12:38:04,880 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- field is : solutionType path is : null
2018-12-26 12:38:04,880 INFO  [http-nio-8180-exec-4] [] [] [diy-CJ] []- Path in non-primitive type is : null for field : solutionType

As you can clearly see, the first line of logger prints class name as : com.paytm.oe.entity.RelatedBusinessSolutionMapping_$$_jvst3bb_5e which should instead be :

com.paytm.oe.entity.RelatedBusinessSolutionMapping

Code for reflection :

public static void setNullFieldInAnObject(Object object,Set<String> value,String path) throws Exception{
        LOGGER.info("In merge diff according to the given set function");
        LOGGER.info("Set is : "+value);
        LOGGER.info("Object is : "+object.toString());
        Class classA= object.getClass();
        LOGGER.info("given class is : "+classA.toString());
        Field fields[]=classA.getDeclaredFields();
        for(int i=0;i<fields.length;i++){
            LOGGER.info("fields are : "+fields[i].toString());
        }
        }

Only in this case it gives a wrong class name which hinders me in iterating inside the class.For all other cases,it's working fine. Please help.





Aucun commentaire:

Enregistrer un commentaire