Java Classes and Web Services

Objects that can be passed to and from web services have to be able to be serialized to an XML type, and then deserialized back to their original type. Objects that are automatically handled are Java primitive types and certain Java standard types, however if you want to create a web service using objects that are not automatically serialized, you can write your own custom serializer.

The objects that can be passed to and from web services are ones that conform to the JavaBean conventions For the purposes of web services, a JavaBean is any Java class that conforms to the following restrictions:

For more information, refer to the JavaBean spec at

Furthermore for web services, each property of the object must be of one of the Java types that maps to an XML schema simple type. These are listed in the table below, which shows the primitive XML Schema types and arrays of primitive XML Schema types supported as parameters and return values for web services. A service method can also accept and return a single piece of XML element data, passed as an org.w3c.dom.Element.

If you want to create a web service for a Java class that uses objects not described in this topic, for example char and char[], or java.util.Collection, you can write a custom serializer to handle the class properly. For more information, see Type Mapping by Hand at the end of this topic.

XML Schema type Java type
string java.lang.String
boolean java.lang.Boolean
decimal java.lang.Double
float java.lang.Float
double java.lang.Double
dateTime java.util.Date
time java.util.Date
date java.util.GregorianCalendar
base64Binary java.lang.Byte[]
normalizedString java.lang.String
integer java.lang.Integer
long java.lang.Long
int java.lang.Integer
short java.lang.Short
byte java.lang.Byte

Type Mapping by Hand

When a type described by the WSDL document cannot be understood by the Web Services Stub/Skeleton generator, an UnknownType placeholder is generated, and class will intentionally not compile. In addition, the generated stub class will contain some comments near the top of the file. To resolve this, you should do the type mapping by hand. You can write your own SOAP serializer/deserializer, which takes the Java type and converts it into a SOAP representation using SOAP encoding rules. You need to describe serializer/deserializer for each Java type in the web service deployment descriptor.

For more information about writing a customer serializer, see .

About Creating J2EE Web Services
About Creating SOAP Web Services
About Creating Stubs to Web Services


Copyright © 1997, 2004, Oracle. All rights reserved.