We’re building a many developer app using JAXB and keep stumbling on problems that all come back to a “version” mismatch between producers and consumers of JAXB objects.
Process hasn’t alleviated the pain so I was thinking about something along the lines of CORBA object versioning for JAXB, maybe via a required final field whose values must match. As an added bonus I’d like to inject the version value as the Maven version # 🙂
This is all using annotations, no xsd.
Thoughts?
Thanks.
—– Clarification —–
Think of this as a Serializable serialVersionUID that is added to the marshal stream when the object is marshaled and is required and whose value is checked when the object is unmarshaled.
Various check rules can be implemented, but in this case I only want equality. If the current version of a Foo is 1.1 and you send me data to unmarshal whose version is anything other than 1.1 I will reject it.
Help?
You could do something like the following:
Foo
Add a version field to your root model object.
Demo
In your demo code leverage a StAX parser to check the version attribute before determining if it is safe to perform the unmarshal operation:
VALID USE CASE
input.xml/Output
INVALID USE CASE
input.xml
Output