I'm using Jackson data format for serializing Pojos as XML.
It is working fine but I would like to remove the namespace definition:
@JacksonXmlRootElement(localName="simple_something")
public class Simple {
public int x = 1;
public int y = 2;
}
I do:
ObjectMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString(new Simple());
I get:
<simple_something xmlns="">
<x>1</x>
<y>2</y>
</simple_something>
but I would like to remove the xmlns=""
and that it looks like
<simple_something>
<x>1</x>
<y>2</y>
</simple_something>
Any ideas?
Make sure to use Woodstox
Stax implementation, and not Stax implementation Oracle bundles with JDK. This is usually done by adding Maven dependency to explicitly include woodstox jar.
This is explained on XML module README at https://github.com/FasterXML/jackson-dataformat-xml/
Oracle's implemention adds that declaration in namespace-repairing mode for some reason. It is also slower and has more bugs, so there's not much reason to rely on it, unless you really want to minimize external dependencies.
Also note that that namespace declaration is completely benign, so while unnecessary it is legal XML. So while it is eyesore all xml tools should work just fine with such extra declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With