You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Richard Wallis <Ri...@talis.com> on 2005/03/07 14:26:33 UTC

Serialise with MinOccurs=0

In axis-1.2RC2, I am having a general problem returning complex messages
with optional elements.  

To try and track down the problem I have created a simple test setup to
pass a simple message and return an identical [but differently named]
message where one of the elements is optional (ie. MinOccurs=0)

<xsd:complexType name="TestUserResponse">
	<xsd:sequence>
		<xsd:element name="VisibleUserIdentifierType"
type="key:IdentifierType"/>
		<xsd:element name="VisibleUserIdentifier"
type="xsd:string" minOccurs="0" />
		<xsd:element name="Desired" type="key:Desired"/>
	</xsd:sequence>
</xsd:complexType>

wsdl2Java provides me with a TestUserResponse.java which is the return
type for my TestLookupSoapBindingImpl class.  If I correctly populate
all the elements of the TestUserResponse object that I return, thus:
 
ret.setVisibleUserIdentifierType(lookupUserRequest.getVisibleUserIdentif
ierType());
 
ret.setVisibleUserIdentifier(lookupUserRequest.getVisibleUserIdentifier(
));
      ret.setDesired(lookupUserRequest.getDesired());
Everything is fine.

If I don't want a  'VisibleUserIdentifier' element which the
minOccurs="0" should allow me to do, I either don't call
'setVisibleUserIdentifier()' or call it with a null value.  In either
case the service returns null to the client thus:
   <soapenv:Body>
      <ns1:lookResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="urn:TestLookup">
         <lookUpReturn xsi:type="ns2:TestUserResponse" xsi:nil="true"
xmlns:ns2="http://schemas.talis.com/ws/Keystone"/>
      </ns1:lookResponse>
   </soapenv:Body></soapenv:Envelope>

I presume that the serialiser is failing to serialise a null element
correctly.

Any idea how I can make it serialise a null element, or instruct it not
to try?

Regards,
	Richard