We have lot of hibernate entity classes with nested relationships. I'm trying to find best way to convert given entity to equivalent json format.
I know about JsonIgnore, Jackson mixins and JsonFilters and have been experimenting with those.
Challenges we are facing are as following
Objects related to each other using OneToMany/JoinColumn or similar annotations - creates infinite recursion.
Utility or meta methods. Jackson seems to be going by getter methods and not by fields. Some of the methods are "meta" method that is not associated with any columns. Example getTotal method can be summing of values of couple of actual fields without having actual total field. Similar case for other cases like getIncomeAccounts which filters accounts based on some criteria.
Jackson Filter I wrote helps a little - it checks if the class field exists based on Jackson property name. It also checks if there annotations such as JoinColumn annotation to avoid recursion if the field exists.
Is there any way I can get metadata from hibernate and use it in my filters? Basically for given entity object, I am interested in knowing if the property Jackson wants to serialize will be mapped to a column and serialize only if there is column value associated with it. Hibernate is certainly aware of properties and column mappings.
Mixins and jsonignore options are workable, but then we depend upon individual developer remembering about putting annotations at appropriate place. Usually forgotten annotations are discovered too late when we really want to get the exported data to analyze some problem and create test case locally.