users@jaxb.java.net

Ideas for the next blog entry

From: Brian Pontarelli <brian_at_pontarelli.com>
Date: Tue, 22 Feb 2005 17:31:25 -0600

Kohsuke,

I just wanted to give you some ideas for your next blog entry. The last
one was great by the way. I've been trying to get the
@XmlJavaTypeAdapter to work with the JAXB 2.0 release and have had no
success at all. Here's are the use cases that I have. I think a few of
them are the same, just variations, but it would be great if you could
cover all of them.


1. Nested complex types and a custom object (this example should be the
same as the Map example, right?):

<xs:complexType name="dataType">
  <xs:attribute name="dataType" value="xs:string"/>
</>

<xs:complexType name="dataValuesType">
  <xs:sequence>
    <xs:element name="data" type="dataType" minOccurs="0"
maxOccurs="unbounded"/>
  </>
</>

<xs:element name="myRootElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="DataValues" type="dataValuesType"/>
    </>
  </>
</>

public class MyRootElement {
  @XmlJavaTypeAdapter(...)
  private MyCustomDataValues foo; // This is custom, not a JAXB class
}



2. Custom enum

<xs:simpleType name="myEnumType">
  <xs:restriction base="xs:NCName">
    <xs:enumeration value="lowerCase1"/>
    <xs:enumeration value="lowerCase2"/>
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="elementWithEnumType">
  <xs:attribute name="enumValue" type="myEnumType"/>
</>

<xs:element name="myRootElement" type="elementWithEnumType"/>

public class MyRootElement {
  @XmlJavaTypeAdapter(...)
  private ENUM_TYPE foo; // This is custom, not a JAXB enum
}


3. Complex type with only attributes and a custom object (this is
probably the same as #1):

<xs:complexType name="dataValuesType">
  <xs:attribute name="value1" value="xs:string"/>
  <xs:attribute name="value2" value="xs:string"/>
  <xs:attribute name="value3" value="xs:string"/>
</>

<xs:element name="myRootElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="DataValues" type="dataValuesType"/>
    </>
  </>
</>

public class MyRootElement {
  @XmlJavaTypeAdapter(...)
  private MyCustomDataValues foo; // This is custom, not a JAXB class
}


4. Simple type:

<xs:element name="myRootElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="versionNumber" type="xs:string"/>
    </>
  </>
</>

public class MyRootElement {
  @XmlJavaTypeAdapter(...)
  private VersionNumber foo; // This is a conversion from String to this
class
}



Thanks,
Brian Pontarelli