如何将Web服务中的'null'值表示为真正的null或空字符串,而不是'null'字符串

编程入门 行业动态 更新时间:2024-10-28 14:26:13
本文介绍了如何将Web服务中的'null'值表示为真正的null或空字符串,而不是'null'字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我正在使用JSF和Java Web Services.当我的任何Web服务函数返回null值时,它始终表示为空"字符串.结果,我无法使用#{empty object}之类的EL表达式来测试null值或空字符串.

In my application, I am using JSF and Java Web Services. When any of my web-service functions return a null value, it is always expressed as a "null" string. As a consequence, I cannot use EL expressions like #{empty object} to test for null values or empty strings.

我想问一下是否有一种配置方法,以使Java Web Services将null值返回为空字符串,或者JSF/EL可以将"null"字符串理解为null值.

I'd like to ask if there's a way to configure such that Java Web Services will return null value as an empty string OR JSF/EL can understand "null" string as null value.

推荐答案

如果您是

  • 使用SOAP,您必须记住SOAP消息是XML,因此您可以将空字符串作为null或empty object

使用HTTP或REST,您必须记住HTTP使用String类型来序列化对象和信息

using HTTP or REST, you must remember that the HTTP using type of String to serialize the object and informations

因此您可以选择:

  • 返回对象的正确序列化.如果使用SOAP,请记住使用Base64编码.

  • right serialization of return objects. If you using SOAP, remember Base64 encoding.

正确的输出值,用于错误.您可以直接序列化异常或自定义消息代码.

right output value for errors. You can serialize directly the exceptions or your custom message codes.

希望对您有所帮助.

更多推荐

如何将Web服务中的'null'值表示为真正的null或空字符串,而不是'null'字符串

本文发布于:2023-11-05 19:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   如何将   而不是   空字符串   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!