How is it possible to make some xjc generated classes subclasses of a custom Exception, such that you can actually throw them, and processable by the JAXBContext? Often webservices return various faults defined that really should be an exception, but since they aren’t you need to wrap them unneccesarily.
Share
Yeah, I finally found something! The Inheritance plugin is able to make the generated classes inherit from classes or implement additional interfaces.
You need to include something like
into the binding file and override getStackTrace() to return null such that it doesn’t get marshalled.
Unfortunately you might run into trouble with some JAXB implementations (see Blaise Doughan’s answer) – I haven’t found a workaround for that yet. So you can either use a not quite nonportable solution, or wrap the JAXB objects into Exceptions.