简体   繁体   English

JAXB,从XML解组,缺少字段为null

[英]JAXB, unmarshalling from XML, missing fields as null

XML inputs are unmarshalled with moxy using namespaces with @XmlPath . 使用@XmlPath命名空间将XML输入与moxy It works fine. 工作正常。 However, if a field from the xml is missing, then it is assigned an empty string after unmarshalling is done. 但是,如果缺少xml中的字段,则在完成编组后会为该字段分配一个空字符串。 I would like however null to be assigned in such cases. 但我希望在这种情况下分配null。 I put two simplified XML examples down below. 我在下面放置了两个简化的XML示例。 I would like the element b to be assigned an empty string in the first example while a null value in the second example. 我希望在第一个示例中为元素b分配一个空字符串,而在第二个示例中为null值。 Do you have any ideas? 你有什么想法? Thank you also in advance. 预先也谢谢你。

e.g. 1.
<ft:root>
    <ft:a>hhh</ft:a>
    <ft:b></ft:b>
</ft:root>


e.g. 2.
<ft:root>
    <ft:a>hhh</ft:a>
</ft:root>

The Problem was solved after I did a mvn clean install. 我执行mvn全新安装后,问题已解决。 Sorry for bothering you. 对不起,打扰你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM