我可以忽略来自@XmlRootElement 的 child 的命名空间吗

Can i ignore child's namespaces from @XmlRootElement

我正在使用 Kotlin 1.3、Java 8 和 Spring 4.0+。

只是我只想将命名空间附加到 <HELLO>,而不是它的子项。 但是,当我使用 @XmlRootElement 为 <HELLO> 定义命名空间时,即使我没有定义任何命名空间,<HI> 也会获得默认命名空间。

@XmlRootElement(name = "HELLO", namespace = "http://www.hello.net")
public class Hello {

    @XmlElement(name = "HI")
    protected Hi hi;

然后

    <HELLO xmlns="http://www.hello.net">
        <HI xmlns=""></HI>
    </HELLO>

有没有办法从 <HI> 中删除 xmlns=""(默认命名空间)?

FYI (after finished with an answer):

I'm developing with Kotlin 1.3. I need to use Java Classes generated from XML using xjc(JAXB), because program(API) spec is handled by XML from external client which will communicate with the APIs.

When use xjc without -npa option there is a package-info.java for apply a same namespace on all of classes generated with just two loc and i exported these classes on my project. (ref:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/xjc.html)

I thought that @XmlSchema(namespace = "namespace1") in package-info.java works well when i register JaxbAnnotationModule() in XmlMapper(with JacksonXmlModule). But, It seems Jackson XmlMapper doesn't fully support xml annotations.

You can solve this problem with below answer or adding XmlMarshaller that add an xmlns to XML.

jackson-dataformat-xml does not support the namespace of package level : https://github.com/FasterXML/jackson-dataformat-xml/issues/18

如果您希望它继承 XML 输出中的 http://www.hello.net,那么您需要为其提供该命名空间。