Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid wstxns1: prefix #666

Open
mailsanchu opened this issue Aug 16, 2024 · 1 comment
Open

How to avoid wstxns1: prefix #666

mailsanchu opened this issue Aug 16, 2024 · 1 comment

Comments

@mailsanchu
Copy link

Given the following classes
RootNamespace.java

@JacksonXmlRootElement(namespace = "namespace1", localName = "RootNamespace")
public class RootNamespace {
    @JacksonXmlProperty(namespace = "namespace1", localName = "childNamespace")
    private ChildNamespace childNamespace;
}

ChildNameSpace.java

public class ChildNamespace {
    @JacksonXmlProperty(namespace = "namespace2", localName = "Name")
    private ThirdLevel thirdLevel;
}

ThirdLevel.java

@Setter
@Getter
public class ThirdLevel {
    @JacksonXmlProperty(namespace = "namespace2", localName = "Name")
    private String name;
}

and It is generating the following output when I convert it into string

<?xml version="1.0" encoding="UTF-8"?>
<RootNamespace xmlns="namespace1">
  <childNamespace>
    <wstxns1:Name xmlns:wstxns1="namespace2"/>
  </childNamespace>
</RootNamespace>

and I would like to generate it the following

<RootNamespace xmlns="namespace1">
    <childNamespace>
        <Name xmlns="namespace2"/>
    </childNamespace>
</RootNamespace>

Is it possible to do. Any help is greatly appreciated.

@cowtowncoder
Copy link
Member

To do this, you will probably need to construct XMLStreamWriter, initialize it with namespace binding, and pass that to XMLMapper.writeValue(). I don't think there is a way to avoid automated namespace declaration generation.
There is a way in Woodstox to re-configure prefix to use, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants