4

For basic i know classloaders have a hierarchy and sequence default classloaders run as below :-

a) bootstrap class loader : runs first and loads all java classes etc.

b) Extclassloader : Extclassloaders loads all ext folder jars and java libraries.

c) Application classloader : As programs execute and linked classes are found they are loaded from classpath using this class loader.

enter image description here

Now, i have pojo classes being generated at run time for various json inputs and Pojo class loaded first seems not being replaced even on using custom class loaders (As Normal class loader first check if class already loaded if loaded do not load a class as per below image normal default class loader behavior).

So now i am stuck at how do i get to know if my classes are being replaced or not? Can i link some listeners to classes in jvm that would let me know class been replaced ? I am looking for debugging steps that i could do debugging reloading or replacing classes process .

Note : it seems using custom class loader used has loaded same class into new custom classloader instance in jvm.

please have look at approach issue(may be) jsonSchema2pojo jackson deserialisation issue that i am still looking answer at. As requirement is to deserialize a json to dynamically created Pojo , what would you suggest a approach when i need to deserialize json after creating pojo classes at runtime as in above question?

Kimchy
  • 501
  • 8
  • 24
  • Eclipse has a special class loader used when debugging, that can detect if class files are changed, and can replace them on the run, if certain criteria are met, EG class level objects are not changed... I do not know how it works, or even if it is what you want... – Usagi Miyamoto Aug 15 '17 at 04:49
  • 2
    You could also enable verbose logging of class loader activity, see: https://stackoverflow.com/a/1705215/4899193 – Usagi Miyamoto Aug 15 '17 at 04:55
  • Thanks Usagi. But can i debug eclipse classloader and apply some listeners to class loading or unloading because i have tried verbose:class as well , it shows unloaded expected class log for once but neven again for life cycle (may be class can be unloaded only once for a classloader .hmm?) , So i am stuck and wish i could do some listeners or something else from suggestion here. – Kimchy Aug 15 '17 at 05:10
  • I think the whole point is: you have to make sure that **your custom** class loader is the first one to load any of these generated classes. In other words - you have to understand how and when *your* custom class loader gets loaded and "activated". – GhostCat Aug 15 '17 at 08:01
  • thanks GhostCat, please have look at approach issue(may be) https://stackoverflow.com/questions/44648092/jsonschema2pojo-jackson-deserialisation-issue that i am still looking answer at. As requirement is to deserialize a json to dynamically created Pojo , what would you suggest a approach when i need to deserialize json after creating pojo classes at runtime as in above question? – Kimchy Aug 15 '17 at 08:12
  • Hi, Kimchy, if you found a solution to your problem outside of StackOverflow, you could answer your own question to help other people. It would be interesting. – Pino Nov 24 '20 at 10:35

0 Answers0