在我的应用程序中,我正在使用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'字符串
发布评论