How to express 'null' value from web servi

2019-07-04 05:03发布

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.

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-07-04 05:53

if you,

  • using SOAP, you must remember that the SOAP message is an XML, so you can return an empty String as null or empty object

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

So you have choose:

  • 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.

I hope to help you.

查看更多
登录 后发表回答