It might be worth mentioning, that in addition to writing an XmlAdapter, which performs the trimming, you can configure XJC to actually use this adapter in generated code. An example of how to do it:
The above example uses the XmlAdapter given in Sahil's answer