【发布时间】:2018-05-01 13:42:30
【问题描述】:
编组 JAXB 类后我有以下 XML:
<?xml version="1.0" encoding="UTF-8"?>
<foo:Object xsi:schemaLocation="http://foo.com/ http://foo.com/foo.xsd"
xmlns:ns0="http://lipsum.com/bar" xmlns:foo="http://foo.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<foo:Some attr1="601"/>
<foo:Others>
<bar:Another xsi:schemaLocation="http://lipsum.com/bar
http://lipsum.com/bar.xsd" xmlns:bar="http://lipsum.com/bar">
<bar:SomeOther attr2="01"/>
</bar:Another>
</foo:Others>
</foo:Object>
jaxb 类中的
@XmlAnyElement(lax = true)
@XmlElementRefs({
@XmlElementRef(name="Another", type=Another.class, required=false)
})
protected List<Object> any;
它可能包含未知数量的具有自己命名空间的其他元素。
问题:
当我编组 Some.class 对象时,jaxb 将 Another.class 的命名空间作为 ns0 放入根元素中,因为我从另一个方法中将
这是一个问题,因为不需要
我需要 @XmlElementRefs 和 @XmlElementRef 注释,因为我需要从 json 转换为 XML,而 Jackson 需要知道“任何”列表可能具有的类型。
我如何告诉 JAXB Oracle/Moxy 实现:
1.- Ignore the namespaces from @XmlElementRef classes during the marshalling.
2.- Remove the not used namespaces aka NS[0-9] prefixes from the root element.
我们将不胜感激。
【问题讨论】:
标签: xml namespaces jaxb moxy jaxb2