Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从 restEasy 服务获取 XML 输出。它工作正常。问题是我看不到没有任何值的元素。我在必要时在域类中使用了@xmlElement。在 Json 响应中,我可以看到具有空值的元素。这不适用于 XML。例如:
JSON响应:“chemStructure”:{“inchi”:null,“inchiKey”:null,“smiles”:null,“iupac”:null,“imageUri”:null,“notation”:null}
XML 响应:
我想至少看到带有空标签的元素
默认情况下,JAXB(这是 RESTEasy 等 JAX-RS 实现的默认绑定层)不会编组空值。nillable您可以通过在 上指定设置来更改此行为@XmlElement。
nillable
@XmlElement
@XmlElement(nillable=true) private String imageUri;
然后null将在 XML 中使用该xsi:nil属性表示一个值。
null
xsi:nil
<imageUri xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
了解更多信息