egeria: Beans do not show all inherited properties in .toString()

I’ve noticed that various beans (for example, EntityDetail) explicitly list the properties to include in their .toString() method – which inevitably contain a mixture of both properties that are defined directly in that bean, as well as other properties that are inherited from one or more superclass’s of that bean.

The problem I’m running into is that since these are defined explicitly in each bean, there are areas where not all of the properties from the superclass’s are included in a subclass’s .toString(). Not sure if this is intentional?

(If not, it would seem advisable to use a super() call to build-up the string from the superclass’s toString()'s to avoid needing to maintain the explicit property lists across all inherited beans…)

The problem I’m running into if it is intentional is that doing a .equals() that fails becomes difficult to debug, because a number of the properties that are used to calculate the .equals() at some level of the class hierarchy are not actually printed out in the toString() method – making the only possible way to detect where things are not equal being going straight into the debugger. (In particular: unit testing frameworks that print out the actual and expected values, using .toString(), will show what appear to be identical expected and actual values, but fail the assertEquals() condition, which is very confusing.)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I had to set ‘Enable getters in code generation’ as per mandy’s screenshot to see the … getters…

Aha – yes, once I’ve enabled that setting I’m able to generate! Thanks, PR updated.

@cmgrote We talked about Lombok recently and I think we said it could be used to automatically generate the equals , hashcode, toString as well as the getters and setters from the annotations.It might be worth considering for the cases you are seeing.