jackson-dataformat-xml
jackson-dataformat-xml copied to clipboard
Support for custom prefix for namespace
This code:
public class Ingredients {
public final String eggs="12";
@JacksonXmlProperty(namespace = "urn:produce:fruit")
public final String bananas="6";
...
}
produces this xml when serialised:
<Ingredients>
<eggs xmlns="">1</eggs>
<wstxns1:bananas xmlns:wstxns1="urn:produce:fruit">
6
</wstxns1:bananas>
</Ingredients>
This works, but I'm missing a way to specify the namespace prefix to use, so I could get
<Ingredients>
<eggs xmlns="">1</eggs>
<fruit:bananas xmlns:fruit="urn:produce:fruit">
6
</wstxns1:bananas>
</Ingredients>
An additional argument to @JacksonXmlProperty would be the obvious way.
Ok, from annotation perspective that could work, although other facilities do not quite exist to pass this information through.
Another possibility would be to pre-declare bindings; to give prefix/URI mapping to either apply to the root element, or as mapping to pass to underlying writer to use if and when necessary.
Doing such mapping is bit tricky from API perspective (since it should be applied via ObjectWriter
, ideally, although perhaps use of XmlMapper
would suffice), but it is something that could then be quite easily passed to XMLStreamWriter
to let it do its job.
Getting stuck on this too, because some services we're consuming do not recognize <wstxns1:SomeOperation>
tag :(
@quaos it would be good to support this, agreed, even though generally I would argue that systems that do not properly handle namespaces (choice of prefix is irrelevant for processing; all that matters is namespace URI it represents. Still, such systems exist so... shrug :)
I think I'll try to tag this as one of "most-wanted" issues, given thumbs-ups.