FasterXML Issues while marsahaling to XML

1.7k Views Asked by At

I am trying to marsahall Objects to XML using jackson-dataformat-xml and woodstax but its adding additional namespace prefix wstxns1. Any suggestions ?

My Beans look like as below

    @JacksonRootElement(localname="Blah" namespace="http://something"
    Bla {

    @JacksonXMLProperty(localname="SomeProperty" namespace="http://something"
    String SomePropety;

 @JacksonXMLProperty(localname="SomeClass" namespace="http://something-different"
    Class SomeClass;
    ....
1

There are 1 best solutions below

2
On

I assume that you want one of following:

  1. Define "default namespace" (one with no prefix) to bind to URI for element, to avoid prefix -- this is only possible for a single namespace at a time. OR,
  2. Make Woodstox use some other base for prefixes it generates as needed
  3. You would like to offer suggestion for prefix to use (since Stax XMLStreamWriter allows this).

Jackson XML module does not have mechanisms for handling prefixes at this point (although RFEs and pull requests are welcome). But Woodstox itself has fair bit of configurability, beyond basic Stax API (which is quite limited).

The places to look beyond (documentation, blogs) for additional configuration properties for output are classes:

  1. org.codehaus.stax2.XMLOutputFactory2 for Stax2 extension properties (implemented by Woodstox and Aalto)
  2. com.ctc.wstx.api.WstxOutputProperties for Woodstox-specific properties

and these properties are set via XMLOutputFactory.setProperty(), same as standard Stax properties.

Property of interest here would be org.codehaus.stax2.XMLOutputFactory2#P_AUTOMATIC_NS_PREFIX, which defaults to "wstxns" but can be changed to any other valid XML id String.

Beyond this, it may be possible to specify pre-configured XMLStreamWriter for Jackson XML module to use. If so, it would also be possible to use standard Stax method ("writeNamespace()" I think?) to create specific prefix-to-URL namespace bindings.

Finally, Jackson mailing lists are the best place to ask questions. Developers like myself do read StackOverflow and other forums as well, but latency tends to be higher as you have noticed.