It appears that the Axis WSDLToJava utility interperates the minOccurs and the nillable="true" attribute in the WSDL as follows:  If minOccurs="0" then the generated Stub class will never send a null value for a field. If minOccurs="1" then the generated Stub class always send a null value for a field. Does anyone know if there are any properties or anything to get the generated Stub classes to optionally send a null field, instead of always sending it or never sending it?
 
The situation I have is that I want to send a partial object to be updated from the Web Services client (i.e. only populate and the fields that should be updated). Assuming that I have a generated Stub class of an object called MyObject, that may have a lot of fields in the wsdl (currently all set to minOccurs="0"), my particular client code only has data to set some of them. My client code looks something like if I want to set a value for one field and delete the value of another field:
 
MyObject obj = new MyObject();
obj.setField1("field1");
obj.setField2(null); 
 
//Code to call the service
MyObjectSoapBindingStub service = getService();
service.update(obj);
 
The problem is that all of the other fields in the generated MyObject Stub (lets say fields 3 - 10) also come out as null in the SOAP message since they were never set by the client code, so there is no way of distinguishing the fact that the client code never modified those fields vs. explicitly setting it to null.
 
I would think that a solution could be that in the Axis Stub generator it could generate the setter methods out so that it sets an internal flag for each field when the setter is called. Then in the code where is actually decides to send the value for a field in the SOAP message, instead of just not including it if the value is null, it could first check the flag and see if the value was actually set and then send it if it was. This would allow client code to distinguish between values that are null because they were just initialized to null from calling new MyObject, or if they were explicitly set to null.
 
Obviously it would be good if this behavior was a standard for WSDLToxxx code generators, so it would work for .Net clients, C++ clients, etc. Does anyone know if this situation has been addressed by any specifications? If not, for Java clients at least, does anyone know of a way to get the Axis WSDLToJava utility to do this?
 
Thanks,
Ben

Reply via email to