相关疑难解决方法(0)

如何防止JAXB在编组期间编写未使用的命名空间

有没有人能够在使用JAXB的对象编组期间删除未使用的命名空间?以下是所请求功能的链接:https://github.com/javaee/jaxb-v2/issues/103(见说明)

是否有为此配置JAXB的属性?这是在MOXy中修复的吗?

我目前正在遍历需要编组的对象并提取所有需要绑定的类Class[] classesToBeBound.然后我创建一个新的JAXBContext.newInstance(classesToBeBound)

现在未使用的命名空间不包含在XML中.

我知道即使使用未使用的命名空间,xml验证也是有效的,但对我来说这是框架应该处理的东西.

以下链接https://blogs.oracle.com/enterprisetechtips/entry/customizing_jaxb提到各种修复(见文中间部分),但是当试图在这些链接中找到解决方案时,链接被破坏或者没有人真正解决它.

欢迎任何评论.

(编辑)纯文字:

GIVEN

a new instance of JAXBContext and add 2 classes with each a separate namespace. 
Run Code Online (Sandbox Code Playgroud)

什么时候

marshalling a class that has these 2 classes as a property but only 1 of them is not null 
Run Code Online (Sandbox Code Playgroud)

然后

I expect only the namespace of the property that is not null to be visible in the XML. 
Run Code Online (Sandbox Code Playgroud)

但是ACTUAL是

that both namespaces are in the xml. …
Run Code Online (Sandbox Code Playgroud)

java xml namespaces jaxb marshalling

20
推荐指数
1
解决办法
3416
查看次数

使用JAXB解组时将空元素转换为null

使用以下JAXB注释定义类:

class Course {
@XmlElement (name = "book")
List<Book> requiredBooks = new ArrayList<Book>();
Run Code Online (Sandbox Code Playgroud)

解组包含此文档的XML文档时

<course>
  ...
  <book/>
</course>
Run Code Online (Sandbox Code Playgroud)

我最终将一个Book添加到列表中,其所有属性都设置为null.我不控制XML输入.如何防止添加此空白书?我尝试拦截set ..()或添加..()方法,但是在处理集合时,JAXB绕过了setter.有什么建议?

java jaxb

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

jaxb ×2

marshalling ×1

namespaces ×1

xml ×1