问题描述
如何全局配置 spring-ws
/ spring-boot-starter-web-services
以序列化空 (null
) 元素?
我不能自己修改序列化的类,所以我不能添加nillable = true
如
public class Response {
@XmlElement(name = "FirstName",required=true,nillable = true)
private String firstName;
}
我希望在响应中所有空元素呈现(以任何形式,但存在),即使它们是null
,例如
<Response>
<FirstName whatever-attribute-here/> <!-- anything here,just the element should be present here even if it is not set in the object -->
</Response>
再一次,我无法修改 Response
类并且它不包含 nillable = true
属性。
我的动机是我要实现响应映射,我想快速检查一下(在开发过程中)我没有遗漏数十个元素中的任何一个。手动将所有省略的元素设置为空字符串(或者更合理的东西)已经是我想要实现的,这是 目标 而不是 way :)
我试图搜索答案,但所有结果都将我带到修改 XML 类本身或将元素设置为空字符串。我相信可能会有一个不错的全局切换 :)
类似于 JSON:我可以全局设置(https://www.baeldung.com/jackson-ignore-null-fields)
mapper.setSerializationInclusion(Include.ALWAYS); // properties are always included,independent of value of the property
或
mapper.setSerializationInclusion(Include.NON_NULL); // only properties with non-null values are to be included
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)