Tuesday, March 22, 2011

Jaxb : Shortcomings of API


JAXB has some shortcomings. Client apps can't customize the marshalling behavior very much. The only standard options are (1) setting the encoding to be used, (2) turn on/off indentation, and (3) add xsi:schemaLocation/xsi:noNamespaceSchemaLocation. You can't even specify how a document should be indented. While you can always plug in some other XML writer, it's not as easy as the rest of JAXB. It would have been easier if Java had a reusable XML writer, like the one in Microsoft .NET. Then the JAXB API could have been designed to work with it.
Further, the ValidationEventHandler interface handles errors during unmarshalling, validation, and marshalling, and ValidationEvent objects represent error information. The problem is that you can't throw ValidationEvent, because it's not throwable. If you compare this with SAX, where you often throw SAXParseException from your ErrorHandler, this is a big difference. I don't claim that the SAX's way is better, but you have to learn yet another way of handling errors.

No comments:

Post a Comment

Chitika