users@jaxb.java.net

Re: White Space Elimination Problem

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 15 Jan 2003 10:49:04 -0800

> I seem to be able to get the behaviour I'm looking for
> by doing the following:
>
> 1. Manually remove the WhiteSpaceProcessor.collapse() calls
> in the calls to my parse method in the generated code.
>
> 2. Set the unmarshaller to not do validation.
>
> 3. Perform manual validation after unmarshalling -
> presumably this works because the strings have already
> been trimmed by my custom parse method.
>
> 4. Perform manual validation before marshalling.
>
> Whilst this may not suit everyone (with the exception of step 1)
> I'm more than happy to pay this as the cost of getting rid of
> a lot of custom code, and reducing development effort.
>
> I'm hoping as per earlier posts that step 1 will go away if
> indeed it is a bug.

It turns out it is indeed a bug of the RI to produce invocation of the
WhitespaceProcessor.collapse() method.

Instead of doing 2, you can relax the schema by removing the maxLength
facet. This doesn't capture your constraint anyway. In this way, you can
rely on the unmarshalling validation to do the rest of the validation,
and your parse method can check if the trimmed string is smaller than 50
characters.

Another thing that I noticed that you are using your TrimmedString class
as a datatype representation, but you can just use the java.lang.String
class by changing the customization to:

        <jxb:javaType name="java.lang.String"
                        xmlType="xsd:string"
                        parse="com.aspective.common.jaxb.TrimmedString.parse"
                        print="toString">


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com