JAXB appending unneeded namespace declarations to tags JAXB appending unneeded namespace declarations to tags xml xml

JAXB appending unneeded namespace declarations to tags


The functionality you are looking for was requested as an enhancement on the JAXB issue tracker in issue 103. The enhancement was declined, since the JAXB authors find it too expensive to traverse the object tree once more before the actual serialization starts to determine which namespaces are actually required.

Although rather bloated, the unnecessary namespaces are not invalidating the XML document. If you really have to save the few bytes and the extra computation cost is affordable, it should be quite easy to write your own XML processor/filter, which takes the JAXB output, parses the document and writes a new document without the unused namespace definitions.