java - How does jackson set private properties without setters? -


i curious how jackson creates objects including it's private properties/fields without setters , using objects empty constructor.

the reason i'm asking when de-serialize properties want automatically set other properties based on these values. example, not want serialize image it's path. once path de-serialized @jsonignore field image can load actual image. after construction of deserialized object fields have not yet been assigned. , getters logically not being called. voodoo magic touching objects private parts?

public class itemtemplate {      private string imagepath;      public itemtemplate() {         system.out.println(imagepath); //still null     }      public string getimagepath() {         system.out.println(imagepath); //not being called when deserializing.         return imagepath;     } } 

but when jackson done de-serializing object has it's imagepath set.

the first comment answered question in title. jackson uses reflection access private , protected properties. somehow led me trying out private setter imagepath field. setter used jackson instead of directly accessing field. within setter set actual image using path string , still remain private.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -