[jackson-xml] custom namespace prefix serialization/de-serialization

4,343 views
Skip to first unread message

Johann Schausberger

unread,
Jan 24, 2018, 10:21:02 AM1/24/18
to jackson-user
Hello,

i am using jackson-dataformat-xml 2.9.3 with woodstox.

My goal i to write namespace prefixes, like this:

<parent xmlns:dc="http://some-url">
  <dc:child>value</dc:child>
<parent>

So the key part is to have a namespace like: xmlns:dc and to use it on child tags/attributes: <dc:child>

Is this possible with jackson?
If not, can this be acheived with overriding some woodstox functionality?



Tatu Saloranta

unread,
Jan 24, 2018, 7:48:41 PM1/24/18
to jackson-user
Adding namespace is easy enough: use `@JacksonXmlProperty` annotation, specifically with `namespace` property set to URI.

There is no way to directly suggest prefix to use; one generated automatically will be used ("wstxns1" etc I think by default).
Since prefixes have no semantics, this should not matter for processors; processing only considers namespace URIs, not prefixes.

If you care deeply about mappings, yes, Woodstox does have means to suggest bindings to use: either for basename ("wstxns"),
or, for suggesting specific prefix for namespace URI. For latter I don't remember if this is via factory or does it require actual
XMLStreamWriter.

-+ Tatu +-

 



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johann Schausberger

unread,
Jan 28, 2018, 4:31:38 PM1/28/18
to jackson-user
thank you for your response!
i unfortunately have to implement a strict format and have to achieve the prefix. i will have a look at streamwriter and factory.

john


On Thursday, January 25, 2018 at 1:48:41 AM UTC+1, Tatu Saloranta wrote:
On Wed, Jan 24, 2018 at 6:48 AM, Johann Schausberger <jschau...@gmail.com> wrote:
Hello,

i am using jackson-dataformat-xml 2.9.3 with woodstox.

My goal i to write namespace prefixes, like this:

<parent xmlns:dc="http://some-url">
  <dc:child>value</dc:child>
<parent>

So the key part is to have a namespace like: xmlns:dc and to use it on child tags/attributes: <dc:child>

Is this possible with jackson?
If not, can this be acheived with overriding some woodstox functionality?


Adding namespace is easy enough: use `@JacksonXmlProperty` annotation, specifically with `namespace` property set to URI.

There is no way to directly suggest prefix to use; one generated automatically will be used ("wstxns1" etc I think by default).
Since prefixes have no semantics, this should not matter for processors; processing only considers namespace URIs, not prefixes.

If you care deeply about mappings, yes, Woodstox does have means to suggest bindings to use: either for basename ("wstxns"),
or, for suggesting specific prefix for namespace URI. For latter I don't remember if this is via factory or does it require actual
XMLStreamWriter.

-+ Tatu +-
 

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages