An issue that sometimes creates confusion when using Web Services is the appropriate mapping of the XML types to Java types and vice versa. JSR-172 uses the mapping shown in the table below to assign XML and Java types.
XML type |
Java type |
---|---|
xsd:string |
java.lang.String |
xsd:int |
Int |
xsd:long |
Long |
xsd:short |
Short |
xsd:boolean |
Boolean |
xsd:byte |
Byte |
xsd:float |
java.lang.String or float |
xsd:double |
java.lang.String or double |
xsd:QName |
javax.xml.namespace.QName |
xsd:base64Binary1 |
byte[] |
xsd:hexBinary1 byte[] |
Byte[] |
Notice that the types xsd:float
and xsd:double
may
be mapped to either the Java types float
and double
or
to String
. This is to account for the fact that the CLDC
1.0 platform doesn't support these types. In a CLDC 1.0 platform, these values
would be converted to a String
using a platform-dependent
format, while in CLDC 1.1 the stub will use the floating-point types. Another
consequence of this fact is that stubs generated for a CLDC 1.1 implementation
may not work properly in CLDC 1.0.
Besides the types indicated in the table above, the basic types may
be mapped not to the primitive Java types but to their wrappers instead. This
is to take into account that these values may be marked as nullable
or
optional and this cannot be represented using the Java primitive types. In
this case the mapping will be done as indicated in the table below.
XML type |
Java type |
---|---|
xsd:int |
java.lang.Integer |
xsd:long |
java.lang.Long |
xsd:short |
java.lang.Short |
xsd:boolean |
java.lang.Boolean |
xsd:byte |
java.lang.Byte |
xsd:float |
java.lang.String or java.lang.Float |
xsd:double |
java.lang.String or java.lang.Double |
Finally the JAX-RPC subset in JSR-172 contains support for arrays and
complex structures enclosed in an xsd:completeType
element.