users@jaxb.java.net

Re: Using javaType to map custom classes

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Fri, 21 Feb 2003 08:19:18 -0700

Dan Lange wrote:

> Has anyone been successful in binding a simple type to a java
> class? Example code would be very helpful.

I have done this before in order to create my own string type to
simulate the behaviour of the java String.trim() function.

  <xsd:simpleType name="trimmedString">
    <xsd:restriction base="xsd:string">
      <xsd:annotation>
        <xsd:appinfo>
          <jxb:javaType name="java.lang.String"
                parse="com.aspective.common.jaxb.TrimmedString.trim"
                print="com.aspective.common.jaxb.TrimmedString.trim">
          </jxb:javaType>
        </xsd:appinfo>
      </xsd:annotation>
    </xsd:restriction>
  </xsd:simpleType>

My class (com.aspective.common.jaxb.TrimmedString) had to be in the
class path at compilation time. (I actually had quite a difficulty
with this, but think it was more to do with Ant issues than JAXB).

> So, as a test, I changed the name attribute to "java.lang.String"
> In which case, I get the following error:
> Specified conversion customization is not used.

I got this message too when I didn't use my customisation.
I guess the JAXB compiler is just questioning why you'd bother to
go to the trouble of defining your own type if you don't use it.

Hope that helps

Marcus