Search

Chapter 34. Using Simple Types

download PDF

Abstract

XML Schema simple types are either XML Schema primitive types like xsd:int, or are defined using the simpleType element. They are used to specify elements that do not contain any children or attributes. They are generally mapped to native Java constructs and do not require the generation of special classes to implement them. Enumerated simple types do not result in generated code because they are mapped to Java enum types.

34.1. Primitive Types

Overview

When a message part is defined using one of the XML Schema primitive types, the generated parameter's type is mapped to a corresponding Java native type. The same pattern is used when mapping elements that are defined within the scope of a complex type. The resulting field is of the corresponding Java native type.

Mappings

Table 34.1, “XML Schema Primitive Type to Java Native Type Mapping” lists the mapping between XML Schema primitive types and Java native types.
Table 34.1. XML Schema Primitive Type to Java Native Type Mapping
XML Schema TypeJava Type
xsd:stringString
xsd:integerBigInteger
xsd:intint
xsd:longlong
xsd:shortshort
xsd:decimalBigDecimal
xsd:floatfloat
xsd:doubledouble
xsd:booleanboolean
xsd:bytebyte
xsd:QNameQName
xsd:dateTimeXMLGregorianCalendar
xsd:base64Binarybyte[]
xsd:hexBinarybyte[]
xsd:unsignedIntlong
xsd:unsignedShortint
xsd:unsignedByteshort
xsd:timeXMLGregorianCalendar
xsd:dateXMLGregorianCalendar
xsd:gXMLGregorianCalendar
xsd:anySimpleType [a] Object
xsd:anySimpleType [b] String
xsd:durationDuration
xsd:NOTATIONQName
[a] For elements of this type.
[b] For attributes of this type.

Wrapper classes

Mapping XML Schema primitive types to Java primitive types does not work for all possible XML Schema constructs. Several cases require that an XML Schema primitive type is mapped to the Java primitive type's corresponding wrapper type. These cases include:
  • An element element with its nillable attribute set to true as shown:
    <element name="finned" type="xsd:boolean"
             nillable="true" />
  • An element element with its minOccurs attribute set to 0 and its maxOccurs attribute set to 1, or its maxOccurs attribute not specified, as shown :
    <element name="plane" type="xsd:string" minOccurs="0" />
  • An attribute element with its use attribute set to optional, or not specified, and having neither its default attribute nor its fixed attribute specified, as shown:
    <element name="date">
      <complexType>
        <sequence/>
        <attribute name="calType" type="xsd:string"
                   use="optional" />
      </complexType>
    </element>
Table 34.2, “Primitive Schema Type to Java Wrapper Class Mapping” shows how XML Schema primitive types are mapped into Java wrapper classes in these cases.
Table 34.2. Primitive Schema Type to Java Wrapper Class Mapping
Schema TypeJava Type
xsd:intjava.lang.Integer
xsd:longjava.lang.Long
xsd:shortjava.lang.Short
xsd:floatjava.lang.Float
xsd:doublejava.lang.Double
xsd:booleanjava.lang.Boolean
xsd:bytejava.lang.Byte
xsd:unsignedBytejava.lang.Short
xsd:unsignedShortjava.lang.Integer
xsd:unsignedIntjava.lang.Long
xsd:unsignedLongjava.math.BigInteger
xsd:durationjava.lang.String
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.