Java toString - ToStringBuilder not sufficient; won't traverse

前端 未结 7 1891
Happy的楠姐
Happy的楠姐 2020-12-07 23:18

I need to be able to traverse through my entire object graph and log all contents of all member fields.

For example: Object A has a collection of Object B\'s which

7条回答
  •  悲&欢浪女
    2020-12-07 23:29

    This link ended up being a good starting point. You basically need something that's recursive but won't get lost in cyclic-references (Object A has a reference to Object B which has reference back to Object A; you dont want to get stuck traversing that over and over again).

    http://www.java2s.com/Code/Java/Class/Constructsprettystringrepresentationofobjectvalue.htm

    This was also somewhat helpful as well

    http://binkley.blogspot.com/2007/08/recursive-tostring.html

提交回复
热议问题