WSDL with type int or blank is not readable by stubs generated by wsdl2java
I have created a simple type
<xsd:simpleType name="IntOrBlank"> <xsd:union memberTypes="xsd:int"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value=""/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
I then create stubs using wsdl2java from axis2, the sending works and receiving seemed to work until I try to obtain the integer value from this type. My code is as such:
IntOrBlank get_part_custom_field7 = each_record.get_part_custom_field7(); Object object = get_part_custom_field7.getObject();
The object is null now. eventhough the SOAP message is coming in as
I trace through the code and I found that wsdl2java has generated the stubs incorrectly. The object that was created was java.math.BigInteger while the stubs did a check to make sure the object is an instance of Integer, as a result, the object is null without throwing any exception. I changed the type to
<xsd:simpleType name="IntOrBlank"> <xsd:union memberTypes="xsd:integer"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value=""/> </xsd:restriction> </xsd:simpleType> </xsd:union> </xsd:simpleType>
and solved the problem
I'd suggest you stop using union that way, maybe not at all.
You've just found one tool that doesn't deal with it the way you'd like - there will be many others. union doesn't really make much sense in this context. What Java type should be used in this case? Object?
What about in this case:
<xs:simpleType name="SillyUnion"> <xs:union memberTypes="xs:int xs:string"/> </xs:simpleType>
What data type would you have wsdl2java use for this? Object again? How would a programmer consuming this data determine whether integer or string data had been included? Do you really mean that everyone using this data should check first?
Union is one of those things that sounded like a good idea at the time, and which has turned out not to be as helpful as was previously thought.