kapua
kapua copied to clipboard
Replacing manual jaxb configuration with class path scan and dependency injection
Implements single point of JAXB configuration through package scan and proper dependency injection.
Related Issue This PR fixes/closes #3426
Description of the solution adopted First of all, the two concerns of creating the creating the JAXB Context and identifying the classes needed have been separated in two different classes: JAXBContextProviderImpl and XmlSerializableClassesProvider respectively. JAXBContextProviderImpl actually accepts a generic list of ClassProvider implementations in order to allow for test cases and/or future expansions (allowing modules to specify their own list of classes to be serialized).
XmlSerializableClassesProvider performs class path scan, looking for all instances of classes declaring the XmlRootElement annotation. The class is initialized with a list of valid packages to scan, and a list of packages to exclude. This is used in conjunction with the guice implementation of the kapua locator, passing the same set of packages declared in the locator.xml (see GuiceLocatorImpl)
Any side note on the changes made This PR includes a number of fixes to issues that emerged during development - some serializable classes had invalid annotations (e.g.: order of field serialization including invalid fields, deserialization instructions referencing non-existing class methods, etc.)