问题
I want to get XJC to use the javaType tag in a complexType when generation beans. Is this not allowed? I'm really missing good documentation and some understandable error message.
Here is what I am trying which fails with the errors:
- compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings.
- (the above customization is attached to the following location in the schema)
Here is the XSD:
<xs:complexType name="MyMap">
<xs:annotation>
<xs:appinfo>
<xjc:javaType name="my.company.HashMapHidingGenerics" adapter="my.company.adapter.MyMapAdapter" />
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="entry" type="MyEntry"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MyEntry">
<xs:attribute name="someAttribute" use="optional"/>
</xs:complexType>
回答1:
Bad news: <javaType>
only supports simple types (see Binding Declarations and Is it possible to use JAXB to map from schema to a java.util.Map?).
However you can achieve what you need by using @XmlAdapter.
来源:https://stackoverflow.com/questions/9844502/xjc-javatype-adapter-in-complextype