I’m just changing design errors made in the past, but want to keep backwards compatibility of my software. For this I would need some way to map two flavors of an xml file into one java bean. Can this be done using two JAXB annotations on one attribute/element? I understand the marshalling would be ambiguous, but the unmarshalling could work. Is there some nice way of doing this?
p.s.: I don’t care about marshalling.
You can map twice:
Or just two XML mappings instead of annotations.
For XML resource mappings, there’s a number of options:
With Annox you can easily map twice using XML mapping resources with different extensions like
MyClass.ann1.xmlorMyClass.ann2.xml. (It’sMyClass.ann.xmlper default, but the adjustment is trivial.)Here’s a sample of what mappings look like: