From: Ian R. <ian...@gm...> - 2009-06-19 16:58:12
|
Currently, Pojomatic ignores annotations on any interfaces a class might implement. Moreover, it is not possible to create a pojomator for an interface, since ClassProperties walks up the superclass hierarchy until it hits Object.class, but the superclass of an interface is null, so we get a NullPointerException. I can see at least two use cases for supporting Pojomators for interfaces: 1. If an interface defines the behavior of equals and hashCode as part of its contract, it could include @Property annotations and a public static Pojomator instance which implementing classes could use for their equals and hashCode implementations. 2. If someone needs to be able to check equality on a subset of properties of SomeClass (independently of SomeClass's equals method), they can define an interface with only those properties, annotate those properties (on the interface) and then have SomeClass implement that interface. Finally, they could use the pojomator for the interface to check equality of just the properties in question. What I would like to propose is that if ClassProperties is constructed for an interface, that it walk up the implementors hierarchy instead of the superclass hierarchy; classes would continue to be handled as they are today. As such, this is a non-breaking change. However, I would not be surprised to see an argument being made that, when constructing ClassProperties for a class, that we should not only examine super classes for annotations, but also interfaces. My personal opinion is that the pojomator for a class should not include properties annotated on any of interfaces which the class implements. If an interface wishes to specify how equals and hashCode should be implemented, it can do so as described in the first use case above. But in general, a class implementation should not need to worry about what annotations might or might not be present on its interfaces. What do others think about this? Should the pojomator for a class include annotated properties from interfaces or not? - Ian |