简体   繁体   English

如何在Jersey JAX-RS实现中编组空字段?

[英]How to marshall null fields in Jersey JAX-RS implementation?

In a Glassfish/Jersey JAX-RS web application, how can I instruct the JSON provider (which defaults to MOXy in Jersey 2.22) to marshall null fields with JSON null value instead of skip them? 在Glassfish / Jersey JAX-RS Web应用程序中,如何指示JSON提供程序(在Jersey 2.22中默认为MOXy)将具有JSON null值的空字段编组而不是跳过它们? I understand the use of @XmlElement(nillable = true) , but since I need it for all classes fields it would be quite cumbersome to add it everywhere. 我了解@XmlElement(nillable = true)的用法,但是由于我在所有类字段中都需要它,因此将其添加到任何地方都非常麻烦。

You can use MOXy @XmlNullPolicy : 您可以使用MOXy @XmlNullPolicy

@XmlNullPolicy(emptyNodeRepresentsNull = true, nullRepresentationForXml = XmlMarshalNullRepresentation.EMPTY_NODE)

Taken from: https://stackoverflow.com/a/11748678/1986499 (Option #2) 摘自: https : //stackoverflow.com/a/11748678/1986499 (选项2)

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

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