tags:

views:

177

answers:

1

How can I remove leading/trailing white space before/while marshalling in JAXB?

+2  A: 

You could use CollapsedStringAdapter:

public class MyClass {

   @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 
   private String field;

}

This adapter removes leading and trailing whitespaces, then truncate any sequnce of tab, CR, LF, and SP by a single whitespace character ' '.

skaffman
is there any way to put this on all fields with String data type when generating classes using xjc?
mabuzer