Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.このコンテンツは選択した言語では利用できません。
34.6. Simple Type Substitution
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
XML allows for simple type substitution between compatible types using the
xsi:type attribute. The default mapping of simple types to Java primitive types, however, does not fully support simple type substitution. The runtime can handle basic simple type substitution, but information is lost. The code generators can be customized to generate Java classes that facilitate lossless simple type substitution.
Default mapping and marshaling リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Because Java primitive types do not support type substitution, the default mapping of simple types to Java primitive types presents problems for supporting simple type substitution. The Java virtual machine will balk if an attempt is made to pass a short into a variable that expects an int even though the schema defining the types allows it.
To get around the limitations imposed by the Java type system, Apache CXF allows for simple type substitution when the value of the element's
xsi:type attribute meets one of the following conditions:
- It specifies a primitive type that is compatible with the element's schema type.
- It specifies a type that derives by restriction from the element’s schema type.
- It specifies a complex type that derives by extension from the element’s schema type.
When the runtime does the type substitution it does not retain any knowledge of the type specified in the element's
xsi:type attribute. If the type substitution is from a complex type to a simple type, only the value directly related to the simple type is preserved. Any other elements and attributes added by extension are lost.
Supporting lossless type substitution リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
You can customize the generation of simple types to facilitate lossless support of simple type substitution in the following ways:
- Set the
globalBindingscustomization element'smapSimpleTypeDeftotrue.This instructs the code generator to create Java value classes for all named simple types defined in the global scope.For more information see Section 38.3, “Generating Java Classes for Simple Types”. - Add a
javaTypeelement to theglobalBindingscustomization element.This instructs the code generators to map all instances of an XML Schema primitive type to s specific class of object.For more information see Section 38.2, “Specifying the Java Class of an XML Schema Primitive”. - Add a
baseTypecustomization element to the specific elements you want to customize.ThebaseTypecustomization element allows you to specify the Java type generated to represent a property. To ensure the best compatibility for simple type substitution, usejava.lang.Objectas the base type.For more information see Section 38.6, “Specifying the Base Type of an Element or an Attribute”.