Alternatively, one can consider defining the application configuration by code, serializing the configuration objects to file as a starting point, and then, as needed, editing the configuration in file format. When the application starts up, it will read in the configuration, de-serialize it back into object form and the application can work with the configuration.
Not unexpectedly, Spring has a way to set up marshallers/unmarshallers for your application so that it is opaque to the application which XML serialization library it is using. This makes it easy to swap out for a different library. I tried three different libraries with Spring and these are my findings:
Library | PROS | CONS |
---|---|---|
JAXB | "The standard for Java"? |
|
Castor | Popular? | Serializes well but on deserializing, get an error of org.springframework.oxm.castor.CastorUnmarshallingFailureException: Castor unmarshalling exception: The class for the root element 'anonymize-settings' could not be found.; nested exception is org.exolab.castor.xml.MarshalException: The class for the root element 'anonymize-settings' could not be found. For whatever reason, Castor doesn't add the xsi:type attribute on the root element when it serializes. |
XStream |
| Not popular? But the library is so simple to use, there is absolutely no learning curve so you don't have to devote a lot of time to it |