I try to serialize some config classes to xml config files using the XMLMapper.
but I have some trouble with the attribute generation. Actually the generated XML is perfect, but XMLMapper adds sometimes a prefix to my attribute names.
One thing that has often caused problems with
XmlMapper is underlying XML Stax library -- one included in JDK sometimes adds unnecessary namespace prefixes.
The solution is to use Woodstox Stax implementation instead, as it is known to work better in general, and also in this specific case.
If you use Maven, you can just add this in your
<dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>woodstox-core-asl</artifactId> <version>4.1.4</version> </dependency>
and your problem may be solved. As an added bonus, this is faster XML parser as well.