{"id":50,"date":"2004-11-23T12:02:52","date_gmt":"2004-11-23T12:02:52","guid":{"rendered":"http:\/\/www.pleus.net\/blog\/?p=50"},"modified":"2010-08-13T00:11:34","modified_gmt":"2010-08-12T22:11:34","slug":"web-services-and-null-values-part-ii","status":"publish","type":"post","link":"https:\/\/www.pleus.net\/blog\/?p=50","title":{"rendered":"Web Services and Null Values &#8211; Part II"},"content":{"rendered":"<p>If you need to transfer an parameter in a Web Service message for which <b>null<\/b> is a legal value always use a custom complex type.<\/p>\n<p>Assume you have the following Web Service method:<br \/>\n<font face=\"courier\"><br \/>\npublic bool isCompany()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return true;<br \/>\n}<br \/>\n<\/font> <br \/>\nIf the requested information is not known it might be good idea to use <b>Boolean<\/b> instead of the native type <b>boolean<\/b> like in the following code snippet:<br \/>\n<font face=\"courier\"><br \/>\npublic Boolean isCompany()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return null; \/\/ that means unknown<br \/>\n}<br \/>\n<\/font> <br \/>\nHere null is returned to indicate that the information is not known.<\/p>\n<p>If you generate the WSDL from this code you will get an <b>xsd:boolean<\/b> on the wire. The result is the same for <b>Boolean<\/b> and <b>boolean<\/b>.<br \/>\nThat means in XML the boolean value is not nullable anymore.<br \/>\nIf you want the transfer a nullable type wrap it in a complex type:<br \/>\n<font face=\"courier\"><br \/>\npublic class WSBoolean<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public boolean;<br \/>\n}<\/p>\n<p>public WSBoolean isCompany()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return null; \/\/ that means unknown<br \/>\n}<br \/>\n<\/font> <\/p>\n<p>I experienced this behaviour on BEA Weblogic 8.1 SP3, but I expect other frameworks\/platforms like .NET or Websphere to behave in the same way.<br \/>\nIf you wrap your nullable types you are on the safe side.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to transfer an parameter in a Web Service message for which null is a legal value always use a custom complex type. Assume you have the following Web Service method: public bool isCompany() { &nbsp;&nbsp;&nbsp;&nbsp;return true; } If the requested information is not known it might be good idea to use Boolean &hellip; <a href=\"https:\/\/www.pleus.net\/blog\/?p=50\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Web Services and Null Values &#8211; Part II<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-soa","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":2,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/334"}],"wp:attachment":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}