FasterXML / FasterXML/woodstox

Allow writing multiple default namespace prefixes

Open
#242 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
259
Forks
90
Avg merge
16h 52m
Merged PRs (30d)
2

Description

When using `jackson-dataformat-xml` and serialising an object with multiple default namespaces, all namespaces other than the first have their prefix auto-generated.

E.g. I want this:
```xml



```
But get this:
```xml



```

Based on [this comment](https://github.com/FasterXML/woodstox/blob/main/src/main/java/com/ctc/wstx/sw/RepairingNsStreamWriter.java#L520-L530) in `RepairingNsStreamWriter`, I'd like to introduce a new [woodstox specific property](https://github.com/FasterXML/woodstox/wiki/Configuring-Woodstox-III-%E2%80%90-Woodstox%E2%80%90Specific-Properties#woodstox-specific-output-properties-formatting) to allow the other option of the suggested functionality: to allow elements to override the default namespace.

The behaviour to generate prefixes automatically appears to get triggered because jackson doesn't invoke the `XMLStreamWriter.writeStartElement()` method using a prefix. This makes sense as jackson doesn't have support for defining namespace prefixes for xml.

I'm happy to have a go at implementing this in a PR if it's functionality you think would suit the project.

I haven't really considered what the behaviour should look like for attributes, and having a cursory play around adding `@JacksonXmlProperty(isAttribute = true, namespace = NS1)` onto my fields isn't giving much clarification but I'm happy to keep digging if you are open to adding support for this.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.